Summary
When creating a worktree in track_mode=auto for a branch that exists only on origin, stdout from git branch --track is mixed into create_worktree output. The returned WORKTREE_PATH becomes contaminated (e.g., starts with Branch 'foo' set up to track 'origin/foo'.), causing postCreate hooks to cd into the wrong path and fail.
Steps to Reproduce
- Ensure branch exists on origin only:
git ls-remote --heads origin <branch> (no local branch).
- Run
git gtr new <branch> (default track_mode=auto).
- Inspect
WORKTREE_PATH passed to postCreate hook or echo the function output.
Expected Behavior
create_worktree stdout contains only the worktree path; WORKTREE_PATH is a clean path and cd "$WORKTREE_PATH" succeeds.
Actual Behavior
git branch --track prints to stdout, which is concatenated with the path. postCreate hook receives a polluted value and cd $WORKTREE_PATH fails (interpreted as cd Branch etc.).
Environment
- Observed on: macOS (git 2.x, zsh)
- Affects: track_mode=auto with remote-only branches; local/none modes and existing local branches are not affected.
Proposed Fix
Redirect git branch --track "$branch" "origin/$branch" stdout (and stderr) to /dev/null in the auto branch creation path, keeping create_worktree stdout clean. A one-line change in lib/core.sh resolves the issue.
Summary
When creating a worktree in
track_mode=autofor a branch that exists only onorigin, stdout fromgit branch --trackis mixed intocreate_worktreeoutput. The returnedWORKTREE_PATHbecomes contaminated (e.g., starts withBranch 'foo' set up to track 'origin/foo'.), causing postCreate hooks tocdinto the wrong path and fail.Steps to Reproduce
git ls-remote --heads origin <branch>(no local branch).git gtr new <branch>(defaulttrack_mode=auto).WORKTREE_PATHpassed to postCreate hook or echo the function output.Expected Behavior
create_worktreestdout contains only the worktree path;WORKTREE_PATHis a clean path andcd "$WORKTREE_PATH"succeeds.Actual Behavior
git branch --trackprints to stdout, which is concatenated with the path. postCreate hook receives a polluted value andcd $WORKTREE_PATHfails (interpreted ascd Branchetc.).Environment
Proposed Fix
Redirect
git branch --track "$branch" "origin/$branch"stdout (and stderr) to/dev/nullin the auto branch creation path, keepingcreate_worktreestdout clean. A one-line change inlib/core.shresolves the issue.