From bdd847ecb49771393e234ae0d74c75a40fa64282 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 6 Feb 2023 18:36:46 -0500 Subject: [PATCH] Creates local branch for remote branch worktrees Removes remote name from remote branch worktrees path --- src/commands/git/worktree.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/commands/git/worktree.ts b/src/commands/git/worktree.ts index 226c01e..de56a97 100644 --- a/src/commands/git/worktree.ts +++ b/src/commands/git/worktree.ts @@ -343,6 +343,12 @@ export class WorktreeGitCommand extends QuickCommand { state.confirm = true; this.canSkipConfirmOverride = undefined; + const isRemoteBranch = state.reference?.refType === 'branch' && state.reference?.remote; + if (isRemoteBranch && !state.flags.includes('-b')) { + state.flags.push('-b'); + state.createBranch = GitReference.getNameWithoutRemote(state.reference); + } + if (state.flags.includes('-b') && state.createBranch == null) { const result = yield* inputBranchNameStep(state, context, { placeholder: 'Please provide a name for the new branch', @@ -558,7 +564,10 @@ export class WorktreeGitCommand extends QuickCommand { const recommendedUri = state.reference != null - ? Uri.joinPath(recommendedRootUri, ...state.reference.name.replace(/\\/g, '/').split('/')) + ? Uri.joinPath( + recommendedRootUri, + ...GitReference.getNameWithoutRemote(state.reference).replace(/\\/g, '/').split('/'), + ) : recommendedRootUri; const recommendedFriendlyPath = truncateLeft(GitWorktree.getFriendlyPath(recommendedUri), 65);