-
Notifications
You must be signed in to change notification settings - Fork 43
Description
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>(defaulttrack_mode=auto). - Inspect
WORKTREE_PATHpassed 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.