Skip to content

Commit

Permalink
fix: needed tracking branch to commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Mar 14, 2021
1 parent cb184a7 commit 619c5d1
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ export default class ObsidianGit extends Plugin {
return;
}

const remote = await this.git.remote([]);

if (!remote) {
this.displayMessage("Failed to detect remote.", 0);
return;
}

if (this.settings.autoPullOnBoot) {
const filesUpdated = await this.pull();

Expand Down Expand Up @@ -131,37 +124,42 @@ export default class ObsidianGit extends Plugin {
const status = await this.git.status();

const currentBranch = status.current;
const trackingBranch = status.tracking;

if (!trackingBranch) {
this.displayError("Did not push. No tracking branch is set!", 10000);
this.setState(PluginState.idle);
return;
}

const changedFiles = status.files;


if (changedFiles.length !== 0) {
await this.add();
await this.commit();
this.displayMessage(`Committed ${changedFiles.length} files`);
} else {
this.displayMessage("No changes to commit");
}

const allChangedFiles = (await this.git.diffSummary([currentBranch, trackingBranch])).files;
if (!this.settings.disablePush) {
const trackingBranch = status.tracking;

if (allChangedFiles.length === 0) {
this.displayMessage("No changes detected");
this.setState(PluginState.idle);
return;
}
if (!trackingBranch) {
this.displayError("Did not push. No upstream branch is set! See README for instructions", 10000);
this.setState(PluginState.idle);
return;
}

if (!this.settings.disablePush) {
if (this.settings.pullBeforePush) {
await this.pull();
const allChangedFiles = (await this.git.diffSummary([currentBranch, trackingBranch])).files;

// Prevent plugin to pull/push at every call of createBackup. Only if unpushed commits are present
if (allChangedFiles.length > 0) {
if (this.settings.pullBeforePush) {
const pulledFilesLength = await this.pull();
if (pulledFilesLength > 0) {
this.displayMessage(`Pulled ${pulledFilesLength} files from remote`);
}
}
await this.push();
this.displayMessage(`Pushed ${allChangedFiles.length} files to remote`);
} else {
this.displayMessage("No changes to push");
this.setState(PluginState.idle);
}
await this.push();
this.displayMessage(`Pushed ${allChangedFiles.length} files to remote`);
}

this.lastUpdate = Date.now();
Expand Down

0 comments on commit 619c5d1

Please sign in to comment.