Skip to content

Commit cb1290b

Browse files
Add create new branch option (create worktree) (microsoft#259599)
* add create branch option on current branch * fix override
1 parent 59c3f0b commit cb1290b

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

extensions/git/src/commands.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,15 +3480,32 @@ export class CommandCenter {
34803480
return;
34813481
}
34823482

3483-
// Check whether the selected branch is checked out in an existing worktree
3484-
const worktree = repository.worktrees.find(worktree => worktree.ref === choice.refId);
3485-
if (worktree) {
3486-
const message = l10n.t('Branch "{0}" is already checked out in the worktree at "{1}".', choice.refName, worktree.path);
3487-
await this.handleWorktreeConflict(worktree.path, message);
3488-
return;
3489-
}
3483+
if (choice.refName === repository.HEAD?.name) {
3484+
const message = l10n.t('Branch "{0}" is already checked out in the current repository.', choice.refName);
3485+
const createBranch = l10n.t('Create New Branch');
3486+
const pick = await window.showWarningMessage(message, { modal: true }, createBranch);
3487+
3488+
if (pick === createBranch) {
3489+
branch = await this.promptForBranchName(repository);
34903490

3491-
commitish = choice.refName;
3491+
if (!branch) {
3492+
return;
3493+
}
3494+
3495+
commitish = 'HEAD';
3496+
} else {
3497+
return;
3498+
}
3499+
} else {
3500+
// Check whether the selected branch is checked out in an existing worktree
3501+
const worktree = repository.worktrees.find(worktree => worktree.ref === choice.refId);
3502+
if (worktree) {
3503+
const message = l10n.t('Branch "{0}" is already checked out in the worktree at "{1}".', choice.refName, worktree.path);
3504+
await this.handleWorktreeConflict(worktree.path, message);
3505+
return;
3506+
}
3507+
commitish = choice.refName;
3508+
}
34923509
}
34933510

34943511
const worktreeName = ((branch ?? commitish).startsWith(branchPrefix)

0 commit comments

Comments
 (0)