Skip to content

Commit

Permalink
Merge pull request #240 from flatironinstitute/commit-nop-if-same
Browse files Browse the repository at this point in the history
Ignore commitFile if contents are identical
  • Loading branch information
WardBrian authored Nov 4, 2024
2 parents 5c88cc6 + e6aa8f9 commit 87fb927
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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

0 comments on commit 87fb927

Please sign in to comment.