@mieweb/wikigdrive
Version:
Google Drive to MarkDown synchronization
42 lines (41 loc) • 1.55 kB
JavaScript
export class GitReset {
constructor(gitScanner) {
Object.defineProperty(this, "gitScanner", {
enumerable: true,
configurable: true,
writable: true,
value: gitScanner
});
Object.defineProperty(this, "executer", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.executer = gitScanner.executer;
}
get debug() {
return this.gitScanner.debug;
}
async resetToLocal(sshParams) {
await this.executer.exec('git checkout main --force', {});
try {
await this.executer.exec('git rebase --abort', { ignoreError: true });
}
catch (ignoredError) { /* empty */ }
await this.gitScanner.executer.exec('git reset --hard HEAD', { env: { ...this.executer.sshOptsEnv(sshParams) } });
await this.gitScanner.removeUntracked();
}
async resetToRemote(remoteBranch, sshParams) {
if (!remoteBranch) {
remoteBranch = 'main';
}
await this.executer.exec(`git fetch origin ${remoteBranch}`, { env: { ...this.executer.sshOptsEnv(sshParams) } });
try {
await this.executer.exec('git rebase --abort', { ignoreError: true });
}
catch (ignoredError) { /* empty */ }
await this.executer.exec(`git reset --hard origin/${remoteBranch}`, { env: { ...this.executer.sshOptsEnv(sshParams) } });
await this.gitScanner.removeUntracked();
}
}