Skip to content

Commit 9cb11b6

Browse files
refactor: use mergeDriver for the merge strategy
- Integrate force param into pullChangesFromRemote - Get rid of the vendored package, use existing mergeDriver
1 parent 37e17d7 commit 9cb11b6

File tree

3 files changed

+7
-32
lines changed

3 files changed

+7
-32
lines changed

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function addCommmands(plugin: ObsidianGit) {
126126
id: "force-pull",
127127
name: "Force pull",
128128
callback: () =>
129-
plugin.promiseQueue.addTask(() => plugin.forcePullChangesFromRemote()),
129+
plugin.promiseQueue.addTask(() => plugin.pullChangesFromRemote(true)),
130130
});
131131

132132
plugin.addCommand({

src/gitManager/isomorphicGit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,10 @@ export class IsomorphicGit extends GitManager {
479479
ours: branchInfo.current,
480480
theirs: branchInfo.tracking!,
481481
abortOnConflict: false,
482-
strategyOption: force ? "theirs" : undefined,
482+
mergeDriver: force ? ({ contents }) => {
483+
const mergedText = contents[2];
484+
return { cleanMerge: true, mergedText };
485+
} : undefined,
483486
})
484487
);
485488
if (!mergeRes.alreadyMerged) {

src/main.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -748,38 +748,10 @@ export default class ObsidianGit extends Plugin {
748748
}
749749

750750
///Used for command
751-
async pullChangesFromRemote(): Promise<void> {
751+
async pullChangesFromRemote(force: boolean = false): Promise<void> {
752752
if (!(await this.isAllInitialized())) return;
753753

754-
const filesUpdated = await this.pull(false);
755-
if (filesUpdated === false) {
756-
return;
757-
}
758-
if (!filesUpdated) {
759-
this.displayMessage("Pull: Everything is up-to-date");
760-
}
761-
762-
if (this.gitManager instanceof SimpleGit) {
763-
const status = await this.updateCachedStatus();
764-
if (status.conflicted.length > 0) {
765-
this.displayError(
766-
`You have conflicts in ${status.conflicted.length} ${
767-
status.conflicted.length == 1 ? "file" : "files"
768-
}`
769-
);
770-
await this.handleConflict(status.conflicted);
771-
}
772-
}
773-
774-
this.app.workspace.trigger("obsidian-git:refresh");
775-
this.setPluginState({ gitAction: CurrentGitAction.idle });
776-
}
777-
778-
///Used for command
779-
async forcePullChangesFromRemote(): Promise<void> {
780-
if (!(await this.isAllInitialized())) return;
781-
782-
const filesUpdated = await this.pull(true);
754+
const filesUpdated = await this.pull(force);
783755
if (filesUpdated === false) {
784756
return;
785757
}

0 commit comments

Comments
 (0)