Skip to content

Commit d6e31bd

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 94047d1 commit d6e31bd

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
@@ -125,7 +125,7 @@ export function addCommmands(plugin: ObsidianGit) {
125125
id: "force-pull",
126126
name: "Force pull",
127127
callback: () =>
128-
plugin.promiseQueue.addTask(() => plugin.forcePullChangesFromRemote()),
128+
plugin.promiseQueue.addTask(() => plugin.pullChangesFromRemote(true)),
129129
});
130130

131131
plugin.addCommand({

src/gitManager/isomorphicGit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,10 @@ export class IsomorphicGit extends GitManager {
430430
ours: branchInfo.current,
431431
theirs: branchInfo.tracking!,
432432
abortOnConflict: false,
433-
strategyOption: force ? "theirs" : undefined,
433+
mergeDriver: force ? ({ contents }) => {
434+
const mergedText = contents[2];
435+
return { cleanMerge: true, mergedText };
436+
} : undefined,
434437
})
435438
);
436439
if (!mergeRes.alreadyMerged) {

src/main.ts

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

728728
///Used for command
729-
async pullChangesFromRemote(): Promise<void> {
729+
async pullChangesFromRemote(force: boolean = false): Promise<void> {
730730
if (!(await this.isAllInitialized())) return;
731731

732-
const filesUpdated = await this.pull(false);
733-
if (filesUpdated === false) {
734-
return;
735-
}
736-
if (!filesUpdated) {
737-
this.displayMessage("Pull: Everything is up-to-date");
738-
}
739-
740-
if (this.gitManager instanceof SimpleGit) {
741-
const status = await this.updateCachedStatus();
742-
if (status.conflicted.length > 0) {
743-
this.displayError(
744-
`You have conflicts in ${status.conflicted.length} ${
745-
status.conflicted.length == 1 ? "file" : "files"
746-
}`
747-
);
748-
await this.handleConflict(status.conflicted);
749-
}
750-
}
751-
752-
this.app.workspace.trigger("obsidian-git:refresh");
753-
this.setPluginState({ gitAction: CurrentGitAction.idle });
754-
}
755-
756-
///Used for command
757-
async forcePullChangesFromRemote(): Promise<void> {
758-
if (!(await this.isAllInitialized())) return;
759-
760-
const filesUpdated = await this.pull(true);
732+
const filesUpdated = await this.pull(force);
761733
if (filesUpdated === false) {
762734
return;
763735
}

0 commit comments

Comments
 (0)