Skip to content

Commit f99d590

Browse files
committed
fix: add command to ask for tracking branch
1 parent 3bb76a5 commit f99d590

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/commands/add.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ export const add = async () => {
6666
"Aborted as worktree wasn't given a name"
6767
);
6868

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);
7074

7175
await shouldPushWorktree(worktree);
7276
} else {

src/helpers/worktree/addNewWorktree.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { executeCommand } from '../general';
22
import { checkIfBranchExistsOnRemote } from '../git';
33
import { calculateNewWorktreePath } from './calculateNewWorktreePath';
44

5-
export const addNewWorktree = async (newBranch: string) => {
5+
export const addNewWorktree = async (
6+
newBranch: string,
7+
trackingBranch?: string
8+
) => {
69
const isExistingBranch = await checkIfBranchExistsOnRemote(newBranch);
710
if (isExistingBranch)
811
throw new Error(`Branch '${newBranch}' already exists.`);
@@ -12,11 +15,10 @@ export const addNewWorktree = async (newBranch: string) => {
1215
const newWorktree = { worktree: newBranch, path: newWorktreePath };
1316

1417
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}`;
1720

18-
const pullCommand = `git -C ${newWorktreePath} pull`;
19-
await executeCommand(pullCommand);
21+
await executeCommand(trackingBranch ? addCommandWithTracking : addCommand);
2022

2123
return newWorktree;
2224
} catch (e: any) {

0 commit comments

Comments
 (0)