Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#14 fix createBackupBranch bug with detecting branch names in use #19

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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