Skip to content

Commit 4baac87

Browse files
authored
Git - polish worktree error handling (microsoft#258806)
1 parent 738b8c8 commit 4baac87

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

extensions/git/src/commands.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,27 +3563,23 @@ export class CommandCenter {
35633563
}
35643564

35653565
private async handleWorktreeError(err: any): Promise<void> {
3566-
const errorMessage = err.stderr;
3567-
const match = errorMessage.match(/worktree at '([^']+)'/) || errorMessage.match(/'([^']+)'/);
3568-
const path = match ? match[1] : undefined;
3569-
3570-
if (!path) {
3566+
const match = err.stderr.match(/^fatal: '([^']+)' is already used by worktree at '([^']+)'/);
3567+
if (!match) {
35713568
return;
35723569
}
35733570

3574-
const worktreeRepository = this.model.getRepository(path) || this.model.getRepository(Uri.file(path));
3571+
const [, branch, path] = match;
3572+
const worktreeRepository = this.model.getRepository(path);
35753573

35763574
if (!worktreeRepository) {
35773575
return;
35783576
}
35793577

3580-
const openWorktree = l10n.t('Open in current window');
3581-
const openWorktreeInNewWindow = l10n.t('Open in new window');
3582-
const message = l10n.t(errorMessage);
3578+
const openWorktree = l10n.t('Open in Current Window');
3579+
const openWorktreeInNewWindow = l10n.t('Open in New Window');
3580+
const message = l10n.t('Branch \'{0}\' is already checked out in the worktree at \'{1}\'.', branch, path);
35833581
const choice = await window.showWarningMessage(message, { modal: true }, openWorktree, openWorktreeInNewWindow);
35843582

3585-
3586-
35873583
if (choice === openWorktree) {
35883584
await this.openWorktreeInCurrentWindow(worktreeRepository);
35893585
} else if (choice === openWorktreeInNewWindow) {

0 commit comments

Comments
 (0)