From 79b5bc611459c60bb4cb8d295be4e59ab0f06f8c Mon Sep 17 00:00:00 2001 From: Max Yu <18641481+maxyu1115@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:35:16 -0800 Subject: [PATCH] Refactor bbinfo file to be an advanced feature not enabled by default. --- CHANGELOG.md | 9 ++ README.md | 17 ++-- package-lock.json | 16 ++-- package.json | 25 +++--- src/branchinfo.ts | 27 +++--- src/extension.ts | 217 +++++++++++++++++++++++++++------------------- 6 files changed, 184 insertions(+), 127 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33da2c8..96801fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## [0.4.0] - 2024-? + +### Changed +- Refactored and made the BranchInfo file an opt-in feature. For the few fans of this feature, you'll need to manually enable it after the update. + +### Fixed +- Removed BranchInfo file caching to avoid bugs related to non-gbs modifications to the file + + ## [0.3.0] - 2023-08-13 ### Changed diff --git a/README.md b/README.md index 4d54b28..39c0ffc 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,14 @@ Git Backup & Sync currently supports the following commands: ## Extension Settings This extension contributes the following settings: -* `git-backup-sync.branchInfoPath`: Points to the location of the branch info file. This defaults to `.branchinfo`. -* `git-backup-sync.defaultBackupUpstreamName`: Name of the default upstream name. This defaults to `origin`. -* `git-backup-sync.defaultAutoBackupBranches`: When creating new backup branches, the new backup branch starts off with `autobackup = defaultAutoBackupBranches`. This defaults to `false`. -* `git-backup-sync.shouldCommitBranchInfoFile`: When creating a new Backup Branch, do you want to commit the branch info file change. (This is useful for sharing across devices). This defaults to `false`. * `git-backup-sync.backupBranchNamePrefix`: The default prefix of the backup branch name. This defaults to `"gbs-backup-"`. +* `git-backup-sync.defaultAutoBackupBranches`: Whether to auto backup upon detecting changes in VSCode. This defaults to `false`. +* `git-backup-sync.defaultBackupUpstreamName`: Name of the default upstream name. This defaults to `origin`. + +And for more customizations using the "branch info" file, there are the following settings: +* `git-backup-sync.branchInfo.enable`: Whether to enable the branch info file. Enabling this file allows for more granular customization per branch, at the cost of needing to manage an additional config file. This defaults to `false`. +* `git-backup-sync.branchInfo.path`: Points to the location of the branch info file. This defaults to `.bbinfo`. +* `git-backup-sync.branchInfo.shouldCommitBranchInfoFile`: When creating a new Backup Branch, do you want to commit the branch info file change. (This is useful for sharing across devices). This defaults to `false`. These settings don't need to be shared and can be different across clones, even including `branchInfoPath`. (But if one wants to sync changes across devices, they need to use the same backup branch. ) @@ -43,4 +46,8 @@ The code for this extension is available on github at: https://github.com/maxyu1 ## Want to Contribute? -I have already created a few issues. Feel free to grab one, work on it, and make a pull request. If you have other ideas, feel free to start a thread in discussions. \ No newline at end of file +I have already created a few issues. Feel free to grab one, work on it, and make a pull request. If you have other ideas, feel free to start a thread in discussions. + +To setup your dev environment, you need `npm` as well as vscode. After cloning, run `npm install` to setup, and F5 to build and run the extension locally. + +And after making your changes, please document a short summary in the `CHANGELOG.md`, following the current format. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8467d38..0c9019d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "git-backup-sync", - "version": "0.2.1", + "version": "0.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "git-backup-sync", - "version": "0.2.1", + "version": "0.3.0", "dependencies": { "simple-git": "^3.16.1" }, @@ -2939,9 +2939,9 @@ } }, "node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -5765,9 +5765,9 @@ } }, "semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "requires": { "lru-cache": "^6.0.0" diff --git a/package.json b/package.json index 2ce45cb..86c8ff4 100644 --- a/package.json +++ b/package.json @@ -46,11 +46,6 @@ "type": "object", "title": "Git Backup & Sync", "properties": { - "git-backup-sync.branchInfoPath": { - "type": "string", - "default": ".bbinfo", - "description": "Path pointing to the Backup Branch Info file. This file stores backup branch information necessary to the extension. " - }, "git-backup-sync.defaultAutoBackupBranches": { "type": "boolean", "default": false, @@ -61,15 +56,25 @@ "default": "origin", "description": "The upstream name we backup to. This defaults to \"origin\"" }, - "git-backup-sync.shouldCommitBranchInfoFile": { - "type": "boolean", - "default": false, - "description": "When creating a new Backup Branch, do you want to commit the branch info file change. (This is useful for sharing across devices)" - }, "git-backup-sync.backupBranchNamePrefix": { "type": "string", "default": "gbs-backup-", "description": "The prefix of backup branch name. This defaults to 'gbs-backup-' " + }, + "git-backup-sync.branchInfo.enabled": { + "type": "boolean", + "default": false, + "description": "Whether to enable the branch info file. Enabling this file allows for more granular customization per branch, at the cost of needing to manage an additional config file." + }, + "git-backup-sync.branchInfo.path": { + "type": "string", + "default": ".bbinfo", + "markdownDescription": "**This only is effective when branchInfo file is enabled**. Path pointing to the Backup Branch Info file. " + }, + "git-backup-sync.branchInfo.shouldCommitBranchInfoFile": { + "type": "boolean", + "default": false, + "markdownDescription": "**This only is effective when branchInfo file is enabled**. When creating a new Backup Branch, do you want to commit the branch info file change. (This is useful for sharing across devices)" } } } diff --git a/src/branchinfo.ts b/src/branchinfo.ts index 4180fc5..d01e79d 100644 --- a/src/branchinfo.ts +++ b/src/branchinfo.ts @@ -1,7 +1,7 @@ import { TextDecoder, TextEncoder } from 'util'; import * as vscode from 'vscode'; -interface BranchInfo { +export interface BranchInfo { autoBackup: boolean, backupBranchName: string, } @@ -9,7 +9,6 @@ interface BranchInfo { export class BranchInfoManager { private workspaceUri: vscode.Uri; - private lastPath?: string; private branchInfoMap: Map = new Map(); private encoder = new TextEncoder(); @@ -17,11 +16,10 @@ export class BranchInfoManager { constructor(workspaceUri: vscode.Uri) { this.workspaceUri = workspaceUri; - this.lastPath = undefined; } - private async readBranchInfoFile() { - let branchInfoUri = this.workspaceUri.with({path: this.workspaceUri.path + "/" + this.lastPath}); + private async readBranchInfoFile(branchInfoPath: string) { + let branchInfoUri = this.workspaceUri.with({path: this.workspaceUri.path + "/" + branchInfoPath}); return vscode.workspace.fs.readFile(branchInfoUri).then(content => { this.branchInfoMap = new Map(); const jsonObject = JSON.parse(this.decoder.decode(content)); @@ -34,8 +32,8 @@ export class BranchInfoManager { }); } - private async updateBranchInfoFile() { - let branchInfoUri = this.workspaceUri.with({path: this.workspaceUri.path + "/" + this.lastPath}); + private async updateBranchInfoFile(branchInfoPath: string) { + let branchInfoUri = this.workspaceUri.with({path: this.workspaceUri.path + "/" + branchInfoPath}); return vscode.workspace.fs.writeFile(branchInfoUri, this.encoder.encode( JSON.stringify(Object.fromEntries(this.branchInfoMap), null, 4) @@ -44,12 +42,7 @@ export class BranchInfoManager { } public async getMap(branchInfoPath: string): Promise> { - if (this.lastPath === branchInfoPath) { - return this.branchInfoMap; - } - this.lastPath = branchInfoPath; - // only read from fs when cache is invalidated - return this.readBranchInfoFile().then(() => this.branchInfoMap); + return this.readBranchInfoFile(branchInfoPath).then(() => this.branchInfoMap); } public async get(branchInfoPath: string, branchName: string): Promise { @@ -64,21 +57,21 @@ export class BranchInfoManager { // this makes sure the branch info map is up to date await this.getMap(branchInfoPath); this.branchInfoMap.set(branchName, branchInfo); - return this.updateBranchInfoFile(); + return this.updateBranchInfoFile(branchInfoPath); } public async delete(branchInfoPath: string, branchName: string) { // this makes sure the branch info map is up to date await this.getMap(branchInfoPath); this.branchInfoMap.delete(branchName); - return this.updateBranchInfoFile(); + return this.updateBranchInfoFile(branchInfoPath); } public async updateAutoBackup(branchInfoPath: string, defaultAutoBackupBranches:boolean) { await this.getMap(branchInfoPath); - this.branchInfoMap.forEach( (_branchInfo,branchName) => { + this.branchInfoMap.forEach( (_branchInfo, branchName) => { _branchInfo.autoBackup = defaultAutoBackupBranches; }); - return this.updateBranchInfoFile(); + return this.updateBranchInfoFile(branchInfoPath); } } \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index d8fcfe2..b4e3c00 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -13,7 +13,7 @@ export function activate(context: vscode.ExtensionContext) { var extension = new GitBackupSync(context); vscode.workspace.onDidChangeConfiguration(() => { - extension.loadConfig(); + extension.reloadConfig(); }); vscode.workspace.onDidSaveTextDocument(async (document: vscode.TextDocument) => { @@ -63,18 +63,39 @@ export function activate(context: vscode.ExtensionContext) { // This method is called when your extension is deactivated export function deactivate() { } -interface IConfig { +interface IBranchInfoConfig { branchInfoPath: string; - defaultBackupUpstreamName: string; - defaultAutoBackupBranches: boolean; shouldCommitBranchInfoFile: boolean; +} + +interface IConfig { backupBranchNamePrefix: string; + defaultAutoBackupBranches: boolean; + defaultBackupUpstreamName: string; + + // Configs only present when branchInfo file is enabled + branchInfoConfig: IBranchInfoConfig | undefined; +} + +function parseConfig(): IConfig { + let branchInfoConfig: IBranchInfoConfig | undefined = undefined; + if (vscode.workspace.getConfiguration('git-backup-sync').get("branchInfo.enabled") === true) { + branchInfoConfig = { + branchInfoPath: vscode.workspace.getConfiguration('git-backup-sync').get("branchInfo.path"), + shouldCommitBranchInfoFile: vscode.workspace.getConfiguration('git-backup-sync').get("branchInfo.shouldCommitBranchInfoFile") + }; + } + return { + backupBranchNamePrefix: vscode.workspace.getConfiguration('git-backup-sync').get("backupBranchNamePrefix"), + defaultAutoBackupBranches: vscode.workspace.getConfiguration('git-backup-sync').get("defaultAutoBackupBranches"), + defaultBackupUpstreamName: vscode.workspace.getConfiguration('git-backup-sync').get("defaultBackupUpstreamName"), + branchInfoConfig: branchInfoConfig + }; } class GitBackupSync { private _outputChannel: vscode.OutputChannel; private _context: vscode.ExtensionContext; - private config: vscode.WorkspaceConfiguration; private _config: IConfig; private _git: git.SimpleGit; @@ -83,8 +104,7 @@ class GitBackupSync { constructor(context: vscode.ExtensionContext) { this._context = context; this._outputChannel = vscode.window.createOutputChannel('Git Backup & Sync'); - this.config = vscode.workspace.getConfiguration('git-backup-sync'); - this._config = this.config; + this._config = parseConfig(); console.log(this._config); if (vscode.workspace.workspaceFolders !== undefined) { @@ -105,25 +125,24 @@ class GitBackupSync { this._context.globalState.update('isEnabled', value); } - public loadConfig(): void { - this.config = vscode.workspace.getConfiguration('git-backup-sync'); - let defaultAutoBackup = this.config.get('defaultAutoBackupBranches'); - let lastDefaultAutoBackup = this._config.defaultAutoBackupBranches; - this._config = this.config; - if (defaultAutoBackup !== lastDefaultAutoBackup) { - if (defaultAutoBackup === true) { - vscode.window.showWarningMessage("Do you want to auto backup all branches?", "Yes", "No").then(selection => { - if (selection === 'Yes') { - //update branchinfo here - this._branchInfo.updateAutoBackup(this._config.branchInfoPath, this._config.defaultAutoBackupBranches); - } - }); - } - else { - vscode.window.showWarningMessage("Do you want to undo auto-backup for all branches?", "Yes", "No").then(selection => { + public reloadConfig(): void { + let lastDefaultAutoBackup: boolean = this._config.defaultAutoBackupBranches; + let branchInfoEnabledBefore: boolean = this._config.branchInfoConfig !== undefined; + // update configs + this._config = parseConfig(); + + let defaultAutoBackup: boolean = this._config.defaultAutoBackupBranches; + let branchInfoEnabledAfter: boolean = this._config.branchInfoConfig !== undefined; + if (branchInfoEnabledAfter) { + let branchInfoPath = ( this._config.branchInfoConfig).branchInfoPath; + if (branchInfoEnabledAfter !== branchInfoEnabledBefore && defaultAutoBackup === lastDefaultAutoBackup) { + this._branchInfo.updateAutoBackup(branchInfoPath, this._config.defaultAutoBackupBranches); + } else if (defaultAutoBackup !== lastDefaultAutoBackup) { + let msg: string = defaultAutoBackup ? "Do you want to auto backup all branches?" : "Do you want to undo auto-backup for all branches?"; + vscode.window.showWarningMessage(msg, "Yes", "No").then(selection => { if(selection === 'Yes') { //update branchinfo here - this._branchInfo.updateAutoBackup(this._config.branchInfoPath, this._config.defaultAutoBackupBranches); + this._branchInfo.updateAutoBackup(branchInfoPath, this._config.defaultAutoBackupBranches); } }); } @@ -142,12 +161,12 @@ class GitBackupSync { * Show message in status bar and output channel. * Return a disposable to remove status bar message. */ - public async showInformationMessage(message: string) { + private async showInformationMessage(message: string) { this.showOutputMessage(message); return await vscode.window.showInformationMessage(message); } - public async showErrorMessage(message: string) { + private async showErrorMessage(message: string) { this.showOutputMessage(message); return await vscode.window.showErrorMessage(message); } @@ -169,12 +188,17 @@ class GitBackupSync { } return this.getCurrentBranchName(branchName).then(currentBranchName => - this._branchInfo.get(this._config.branchInfoPath, currentBranchName).then(v => { - if (v === undefined) { - return false; + { + if (this._config.branchInfoConfig === undefined) { + return this._config.defaultAutoBackupBranches; } - return v.autoBackup; - }) + return this._branchInfo.get(this._config.branchInfoConfig.branchInfoPath, currentBranchName).then(v => { + if (v === undefined) { + return false; + } + return v.autoBackup; + }); + } ); } @@ -193,6 +217,19 @@ class GitBackupSync { } } + private async getBackupBranchName(currentBranchName: string): Promise { + if (this._config.branchInfoConfig === undefined) { + return this._config.backupBranchNamePrefix + currentBranchName; + } + return this._branchInfo.getMap(this._config.branchInfoConfig.branchInfoPath).then(branchInfoMap => { + let backupBranchInfo= branchInfoMap.get(currentBranchName); + if (backupBranchInfo === undefined) { + return undefined; + } + return backupBranchInfo.backupBranchName; + }); + } + public async createBackupBranch(branchName?: string): Promise { if (!this.isEnabled) { return; @@ -200,22 +237,26 @@ class GitBackupSync { let currentBranchName: string = await this.getCurrentBranchName(branchName); this.showOutputMessage(`Creating Backup Branch for "${currentBranchName}"`); - let branchInfoMap = await this._branchInfo.getMap(this._config.branchInfoPath); + let backupBranchName: string = this._config.backupBranchNamePrefix + currentBranchName; - if (branchInfoMap.has(currentBranchName)) { - this.showErrorMessage(`Create Backup Branch failed: "${currentBranchName}" already has a backup branch, aborting`); - return; - } + if (this._config.branchInfoConfig !== undefined) { + let branchInfoMap = await this._branchInfo.getMap(this._config.branchInfoConfig.branchInfoPath); - let backupBranchName = await vscode.window.showInputBox({ - placeHolder: "Type a Branch Name, or press ENTER and use the default", - prompt: "Create Backup Branch with Name" - }); - if (backupBranchName === undefined) { - this.showInformationMessage("Create Backup Branch cancelled"); - return; + if (branchInfoMap.has(currentBranchName)) { + this.showErrorMessage(`Create Backup Branch failed: "${currentBranchName}" already has a backup branch, aborting`); + return; + } + + let inputBackupBranchName = await vscode.window.showInputBox({ + placeHolder: "Type a Branch Name, or press ENTER and use the default", + prompt: "Create Backup Branch with Name" + }); + if (inputBackupBranchName === undefined) { + this.showInformationMessage("Create Backup Branch cancelled"); + return; + } + backupBranchName = (inputBackupBranchName !== "") ? inputBackupBranchName : backupBranchName; } - backupBranchName = (backupBranchName !== "") ? backupBranchName : (this._config.backupBranchNamePrefix + currentBranchName); let allBranches = (await this._git.branch()).branches; let allBranchNames = new Set(); @@ -236,14 +277,16 @@ class GitBackupSync { return; } - await this._branchInfo.update(this._config.branchInfoPath, currentBranchName, { - autoBackup: this._config.defaultAutoBackupBranches, - backupBranchName: backupBranchName, - }); + if (this._config.branchInfoConfig !== undefined) { + await this._branchInfo.update(this._config.branchInfoConfig.branchInfoPath, currentBranchName, { + autoBackup: this._config.defaultAutoBackupBranches, + backupBranchName: backupBranchName, + }); + } // unstage current changes console.log(await this._git.reset()); - if (this._config.shouldCommitBranchInfoFile) { - console.log(await this._git.add(this._config.branchInfoPath)); + if (this._config.branchInfoConfig !== undefined && this._config.branchInfoConfig.shouldCommitBranchInfoFile) { + console.log(await this._git.add(this._config.branchInfoConfig.branchInfoPath)); console.log(await this._git.commit(`git-backup-sync: create backup branch for [${currentBranchName}]`)); } console.log(await this._git.branch([backupBranchName, currentBranchName])); @@ -258,16 +301,16 @@ class GitBackupSync { let currentBranchName: string = await this.getCurrentBranchName(branchName); this.showOutputMessage(`Retiring Backup Branch for "${currentBranchName}"`); - let branchInfoMap = await this._branchInfo.getMap(this._config.branchInfoPath); - let backupBranchInfo = branchInfoMap.get(currentBranchName); - - if (backupBranchInfo === undefined) { + let backupBranchName = await this.getBackupBranchName(currentBranchName); + if (backupBranchName === undefined) { this.showErrorMessage(`Retire Backup Branch Aborted: "${currentBranchName}" doesn't have a backup branch, aborting`); return; } - console.log(await this._branchInfo.delete(this._config.branchInfoPath, currentBranchName)); - console.log(await this._git.deleteLocalBranch(backupBranchInfo.backupBranchName)); + if (this._config.branchInfoConfig !== undefined) { + console.log(await this._branchInfo.delete(this._config.branchInfoConfig.branchInfoPath, currentBranchName)); + } + console.log(await this._git.deleteLocalBranch(backupBranchName)); // TODO: undo the "git-backup-sync: create backup branch" commit? } @@ -280,17 +323,15 @@ class GitBackupSync { let currentBranchName: string = await this.getCurrentBranchName(branchName); this.showOutputMessage(`Syncing Backup Branch for "${currentBranchName}"`); - let branchInfoMap = await this._branchInfo.getMap(this._config.branchInfoPath); - let backupBranchInfo = branchInfoMap.get(currentBranchName); - - if (backupBranchInfo === undefined) { + let backupBranchName = await this.getBackupBranchName(currentBranchName); + if (backupBranchName === undefined) { this.showErrorMessage(`Sync Backup Branch Aborted: "${currentBranchName}" doesn't have a backup branch, aborting`); return; } // by recreating the local backup branch, we make sure the local backup branch is in sync to the local branch - console.log(await this._git.deleteLocalBranch(backupBranchInfo.backupBranchName)); - console.log(await this._git.branch([backupBranchInfo.backupBranchName, currentBranchName])); + console.log(await this._git.deleteLocalBranch(backupBranchName)); + console.log(await this._git.branch([backupBranchName, currentBranchName])); } public async backup(branchName?: string): Promise { @@ -300,13 +341,13 @@ class GitBackupSync { let currentBranchName = await this.getCurrentBranchName(branchName); this.showOutputMessage(`Backing up Current Branch "${currentBranchName}"`); - let branchInfo = await this._branchInfo.get(this._config.branchInfoPath, currentBranchName); - if (branchInfo === undefined) { + let backupBranchName = await this.getBackupBranchName(currentBranchName); + if (backupBranchName === undefined) { this.showErrorMessage("Backup failed: no backup branch found. Please create backup branch first"); return; } - let backupBranchName: string = branchInfo.backupBranchName; + let failed = false; // unstages current changes console.log(await this._git.reset()); try { @@ -320,12 +361,26 @@ class GitBackupSync { } // stage and commits current changes to backup branch console.log(await this._git.add(".")); - console.log(await this._git.commit(`git-backup-sync: backup commit [${randomUUID()}]`)); - // force pushes since we are rewriting git history - console.log(await this._git.push(this._config.defaultBackupUpstreamName, backupBranchName, ["--force"])); - // IMPORTANT: the local backup branch is ALWAYS maintained in a state in sync with your local branch - // It is therefore always lagging behind the upstream backup branch. - console.log(await this._git.reset(["--mixed", "HEAD~1"])); + try { + console.log(await this._git.commit(`git-backup-sync: backup commit [${randomUUID()}]`)); + } catch(exception) { + failed = true; + console.log(await this._git.reset()); + } + if (!failed) { + try { + // force pushes since we are rewriting git history + console.log(await this._git.push(this._config.defaultBackupUpstreamName, backupBranchName, ["--force"])); + } catch(exception) { + failed = true; + this.showErrorMessage(`Backup failed: force push to ${this._config.defaultBackupUpstreamName}/${backupBranchName} failed`); + } + } + if (!failed) { + // IMPORTANT: the local backup branch is ALWAYS maintained in a state in sync with your local branch + // It is therefore always lagging behind the upstream backup branch. + console.log(await this._git.reset(["--mixed", "HEAD~1"])); + } console.log(await this._git.checkout(currentBranchName)); } @@ -341,9 +396,8 @@ class GitBackupSync { return false; } - let backupBranchName: string; - let branchInfo = await this._branchInfo.get(this._config.branchInfoPath, currentBranchName); - if (branchInfo === undefined) { + let backupBranchName = await this.getBackupBranchName(currentBranchName); + if (backupBranchName === undefined) { ///ask user if they want to loadBackup by giving a backup Branch name let branchName = await vscode.window.showInputBox({ placeHolder: 'No backup branch found.Type a Branch Name, or press Esc to cancel', @@ -358,26 +412,15 @@ class GitBackupSync { backupBranchName = branchName; } - else { - backupBranchName = branchInfo.backupBranchName; - } + // TODO: add check to confirm branch exists upstream - - /* - let branchInfo = await this._branchInfo.get(this._config.branchInfoPath, currentBranchName); - if (branchInfo === undefined) { - this.showErrorMessage(`Load Backup failed: No backup branch found for "${currentBranchName}"`); - return false; - } - let backupBranchName: string = branchInfo.backupBranchName; - */ // stashes the current changes. Normally this shouldn't do anything since you wouldn't want to load backup with local changes console.log(await this._git.stash()); console.log(await this._git.checkout(backupBranchName)); console.log(await this._git.fetch()); // pulls in the most up to date backup branch console.log(await this._git.reset(["--hard", this._config.defaultBackupUpstreamName + "/" + backupBranchName])); - + // Check if backup branch is out of sync // only acceptable output is "0 1", where backup branch is ahead by only 1 commit; which is the backup commit let checkResult = await this.checkBranchesInSync(currentBranchName, backupBranchName, 0, 1);