Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore commitFile if contents are identical #240

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gui/src/app/Project/ProjectReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const ProjectReducer = (s: ProjectDataModel, a: ProjectReducerAction) => {
return { ...s, ephemera: newEphemera };
}
case "commitFile": {
if (s[a.filename] === s.ephemera[a.filename]) {
return s;
}
const newState = { ...s };
const newDataSource = confirmDataSourceForCommit(
s.meta.dataSource,
Expand Down
33 changes: 32 additions & 1 deletion gui/test/app/Project/ProjectReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ describe("Project reducer", () => {
ephemera: { ...ephemeralFiles },
meta: { dataSource: DataSource.GENERATED_BY_PYTHON },
} as any as ProjectDataModel;

const editAction: ProjectReducerAction = {
type: "editFile",
content: "new content",
filename: ProjectKnownFiles.DATAFILE,
};
const commitAction: ProjectReducerAction = {
type: "commitFile",
filename: ProjectKnownFiles.DATAFILE,
Expand Down Expand Up @@ -181,11 +187,36 @@ describe("Project reducer", () => {
...initialState,
meta: { dataSource: p.source },
} as any as ProjectDataModel;
const edit = { ...editAction, filename: p.file };
const edited = ProjectReducer(initial, edit);
const commit = { ...commitAction, filename: p.file };
const result = ProjectReducer(initial, commit);
const result = ProjectReducer(edited, commit);
expect(result.meta.dataSource).toEqual(p.newSource);
});
});

test("Commiting identical data generation script does not change status", () => {
const pairs = [
{
source: DataSource.GENERATED_BY_PYTHON,
file: ProjectKnownFiles.DATAPYFILE,
},
{
source: DataSource.GENERATED_BY_R,
file: ProjectKnownFiles.DATARFILE,
},
];
pairs.forEach((p) => {
const initial = {
...initialState,
meta: { dataSource: p.source },
} as any as ProjectDataModel;

const commit = { ...commitAction, filename: p.file };
const result = ProjectReducer(initial, commit);
expect(result.meta.dataSource).toEqual(p.source);
});
});
test("Saving data generation script does not change status for data.json it didn't generate", () => {
const pairs = [
{
Expand Down