Skip to content

Commit 27d817a

Browse files
committed
refactor: minor rephrasing and restructure
1 parent 263e675 commit 27d817a

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export function addCommmands(plugin: ObsidianGit) {
213213
if (Platform.isDesktopApp) {
214214
plugin.addCommand({
215215
id: "commit-amend-staged-specified-message",
216-
name: "Commit Amend",
216+
name: "Amend staged",
217217
callback: () =>
218218
plugin.promiseQueue.addTask(() =>
219219
plugin.commit({

src/main.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ export default class ObsidianGit extends Plugin {
667667
) {
668668
await this.push();
669669
} else {
670-
this.displayMessage("No changes to push");
670+
this.displayMessage("No commits to push");
671671
}
672672
}
673673
this.setPluginState({ gitAction: CurrentGitAction.idle });
@@ -717,28 +717,33 @@ export default class ObsidianGit extends Plugin {
717717
return false;
718718
}
719719
changedFiles = [...status.changed, ...status.staged];
720-
} else if (fromAuto && hadConflict) {
721-
this.displayError(
722-
`Did not commit, because you have conflicts. Please resolve them and commit per command.`
723-
);
724-
return false;
725-
} else if (hadConflict) {
726-
await this.mayDeleteConflictFile();
727-
status = await this.updateCachedStatus();
728-
changedFiles = [...status.changed, ...status.staged];
729720
} else {
730-
if (onlyStaged) {
731-
changedFiles = await (
732-
this.gitManager as IsomorphicGit
733-
).getStagedFiles();
721+
// isomorphic-git section
722+
723+
if (fromAuto && hadConflict) {
724+
// isomorphic-git doesn't have a way to detect current
725+
// conflicts, they are only detected on commit
726+
//
727+
// Conflicts should only be resolved by manually committing.
728+
this.displayError(
729+
`Did not commit, because you have conflicts. Please resolve them and commit per command.`
730+
);
731+
return false;
732+
} else if (hadConflict) {
733+
await this.mayDeleteConflictFile();
734+
status = await this.updateCachedStatus();
735+
changedFiles = [...status.changed, ...status.staged];
734736
} else {
735-
unstagedFiles = await (
736-
this.gitManager as IsomorphicGit
737-
).getUnstagedFiles();
738-
changedFiles = unstagedFiles.map(({ filepath }) => ({
739-
vault_path:
740-
this.gitManager.getRelativeVaultPath(filepath),
741-
}));
737+
const gitManager = this.gitManager as IsomorphicGit;
738+
if (onlyStaged) {
739+
changedFiles = await gitManager.getStagedFiles();
740+
} else {
741+
unstagedFiles = await gitManager.getUnstagedFiles();
742+
changedFiles = unstagedFiles.map(({ filepath }) => ({
743+
vault_path:
744+
this.gitManager.getRelativeVaultPath(filepath),
745+
}));
746+
}
742747
}
743748
}
744749

@@ -864,7 +869,7 @@ export default class ObsidianGit extends Plugin {
864869
} to remote`
865870
);
866871
} else {
867-
this.displayMessage(`No changes to push`);
872+
this.displayMessage(`No commits to push`);
868873
}
869874
}
870875
this.setPluginState({ offlineMode: false });
@@ -1250,8 +1255,10 @@ I strongly recommend to use "Source mode" for viewing the conflicted files. For
12501255
} else {
12511256
this.log("Encountered network error, but already in offline mode");
12521257
}
1253-
this.setPluginState({ offlineMode: true });
1254-
this.setPluginState({ gitAction: CurrentGitAction.idle });
1258+
this.setPluginState({
1259+
gitAction: CurrentGitAction.idle,
1260+
offlineMode: true,
1261+
});
12551262
}
12561263

12571264
// region: displaying / formatting messages

0 commit comments

Comments
 (0)