File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,11 @@ export const add = async () => {
66
66
"Aborted as worktree wasn't given a name"
67
67
) ;
68
68
69
- worktree = await addNewWorktree ( newBranch ) ;
69
+ let trackingBranch = await window . showQuickPick ( remoteBranches , {
70
+ placeHolder : 'Select remote branch to track' ,
71
+ } ) ;
72
+
73
+ worktree = await addNewWorktree ( newBranch , trackingBranch ) ;
70
74
71
75
await shouldPushWorktree ( worktree ) ;
72
76
} else {
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ import { executeCommand } from '../general';
2
2
import { checkIfBranchExistsOnRemote } from '../git' ;
3
3
import { calculateNewWorktreePath } from './calculateNewWorktreePath' ;
4
4
5
- export const addNewWorktree = async ( newBranch : string ) => {
5
+ export const addNewWorktree = async (
6
+ newBranch : string ,
7
+ trackingBranch ?: string
8
+ ) => {
6
9
const isExistingBranch = await checkIfBranchExistsOnRemote ( newBranch ) ;
7
10
if ( isExistingBranch )
8
11
throw new Error ( `Branch '${ newBranch } ' already exists.` ) ;
@@ -12,11 +15,10 @@ export const addNewWorktree = async (newBranch: string) => {
12
15
const newWorktree = { worktree : newBranch , path : newWorktreePath } ;
13
16
14
17
try {
15
- const worktreeAddCommand = `git worktree add -B ${ newBranch } ${ newWorktreePath } ` ;
16
- await executeCommand ( worktreeAddCommand ) ;
18
+ const addCommand = `git worktree add -B ${ newBranch } ${ newWorktreePath } ` ;
19
+ const addCommandWithTracking = `git worktree add --track -B ${ newBranch } ${ newWorktreePath } origin/ ${ trackingBranch } ` ;
17
20
18
- const pullCommand = `git -C ${ newWorktreePath } pull` ;
19
- await executeCommand ( pullCommand ) ;
21
+ await executeCommand ( trackingBranch ? addCommandWithTracking : addCommand ) ;
20
22
21
23
return newWorktree ;
22
24
} catch ( e : any ) {
You can’t perform that action at this time.
0 commit comments