Skip to content

Commit

Permalink
fix: ask for upstream branch in backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Mar 14, 2024
1 parent 6a89424 commit d1143f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/gitManager/simpleGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,11 @@ export class SimpleGit extends GitManager {
return true;
}
const status = await this.git.status((err) => this.onError(err));
const trackingBranch = status.tracking!;
const trackingBranch = status.tracking;
const currentBranch = status.current!;
if (!trackingBranch) {
return false;
}
const remoteChangedFiles = (
await this.git.diffSummary([currentBranch, trackingBranch, "--"])
).changed;
Expand Down
14 changes: 9 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export default class ObsidianGit extends Plugin {
this.addCommand({
id: "set-upstream-branch",
name: "Set upstream branch",
callback: async () => this.setUpsreamBranch(),
callback: async () => this.setUpstreamBranch(),
});

this.addCommand({
Expand Down Expand Up @@ -995,12 +995,16 @@ export default class ObsidianGit extends Plugin {
requestCustomMessage,
commitMessage,
}))
)
) {
return;
}

if (!this.settings.disablePush) {
// Prevent plugin to pull/push at every call of createBackup. Only if unpushed commits are present
if (await this.gitManager.canPush()) {
if (
(await this.remotesAreSet()) &&
(await this.gitManager.canPush())
) {
if (
this.settings.syncMethod != "reset" &&
this.settings.pullBeforePush
Expand Down Expand Up @@ -1409,12 +1413,12 @@ export default class ObsidianGit extends Plugin {
}
if (!(await this.gitManager.branchInfo()).tracking) {
new Notice("No upstream branch is set. Please select one.");
return await this.setUpsreamBranch();
return await this.setUpstreamBranch();
}
return true;
}

async setUpsreamBranch(): Promise<boolean> {
async setUpstreamBranch(): Promise<boolean> {
const remoteBranch = await this.selectRemoteBranch();

if (remoteBranch == undefined) {
Expand Down

0 comments on commit d1143f7

Please sign in to comment.