Skip to content

Commit

Permalink
#14 fix createBackupBranch bug with detecting branch names in use
Browse files Browse the repository at this point in the history
  • Loading branch information
maxyu1115 committed Mar 24, 2023
1 parent df71da0 commit e045e51
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class GitBackupSync {
return;
}

let backupBranchNames = new Set(Array.from(branchInfoMap.values()).map(info => info.backupBranchName));
let backupBranchName = await vscode.window.showInputBox({
placeHolder: "Type a Branch Name, or press ENTER and use the default",
prompt: "Create Backup Branch with Name"
Expand All @@ -181,15 +180,26 @@ class GitBackupSync {
return;
}
backupBranchName = (backupBranchName !== "") ? backupBranchName : "gbs-backup-" + currentBranchName;
if (backupBranchNames.has(backupBranchName)) {
this.showErrorMessage(`Create Backup Branch failed: intended backup branch name "${backupBranchName}" already exists`);
return;

let allBranches = (await this._git.branch()).branches;
let allBranchNames = new Set();
let remotePrefix = `remotes/${this._config.defaultBackupUpstreamName}/`;
for (let name in allBranches) {
if (name.startsWith("remotes/")) {
// we only need to prevent same names for the desired backup remote+local, other remotes don't matter
if (name.startsWith(remotePrefix)) {
allBranchNames.add(name.substring(remotePrefix.length));
}
} else {
allBranchNames.add(name);
}
}

if (branchInfoMap.has(currentBranchName)) {
this.showErrorMessage(`Create Backup Branch failed: "${currentBranchName}" already has a backup branch, aborting`);
if (allBranchNames.has(backupBranchName)) {
this.showErrorMessage(`Create Backup Branch failed: intended backup branch name "${backupBranchName}" already exists`);
return;
}

await this._branchInfo.update(this._config.branchInfoPath, currentBranchName, {
autoBackup: this._config.defaultAutoBackupBranches,
backupBranchName: backupBranchName,
Expand Down

0 comments on commit e045e51

Please sign in to comment.