Skip to content

Conversation

@ueryooo
Copy link

@ueryooo ueryooo commented Dec 6, 2025

Description

Silence git branch --track output in auto mode so create_worktree returns only the worktree path.

Motivation

In ‎track_mode=auto with a remote-only branch, ‎git branch --track printed to stdout, which was concatenated into ‎WORKTREE_PATH; postCreate hooks then failed when ‎cd "$WORKTREE_PATH" was interpreted as ‎cd Branch ...; this change keeps stdout clean by discarding the tracking command output.

Fixes #32

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Other (please describe):

Testing

Manual Testing Checklist

Tested on:

  • macOS
  • Linux (specify distro: **_**)
  • Windows (Git Bash)

Core functionality tested:

  • git gtr new <branch> - Create worktree
  • git gtr go <branch> - Navigate to worktree
  • git gtr editor <branch> - Open in editor (if applicable)
  • git gtr ai <branch> - Start AI tool (if applicable)
  • git gtr rm <branch> - Remove worktree
  • git gtr list - List worktrees
  • git gtr config - Configuration commands (if applicable)
  • Other commands affected by this change: **__**

Test Steps

  1. Ensure branch exists on origin only (no local branch);
  2. Run ‎git gtr new <branch> (track_mode=auto);
  3. Confirm ‎WORKTREE_PATH equals the created worktree path with no extra text
  4. Run postCreate hook or ‎cd "$WORKTREE_PATH"; it succeeds.

Expected behavior:

create_worktree stdout is just the worktree path; hooks can cd successfully.

Actual behavior:

Matches expected after the change.

Breaking Changes

  • This PR introduces breaking changes
  • I have discussed this in an issue first
  • Migration guide is included in documentation

Checklist

Before submitting this PR, please check:

  • I have read CONTRIBUTING.md
  • My code follows the project's style guidelines
  • I have performed manual testing on at least one platform
  • I have updated documentation (README.md, CLAUDE.md, etc.) if needed
  • My changes work on multiple platforms (or I've noted platform-specific behavior)
  • I have added/updated shell completions (if adding new commands or flags)
  • I have tested with both git gtr (production) and ./bin/gtr (development)
  • No new external dependencies are introduced (Bash + git only)
  • All existing functionality still works

Additional Context


License Acknowledgment

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0.

Summary by CodeRabbit

  • Chores
    • Minor internal maintenance update with no end-user visible changes.

✏️ Tip: You can customize this high-level summary in your review settings.

Changes:\n- redirect git branch --track stdout/stderr to /dev/null when auto-creating a local tracking branch\n- prevent WORKTREE_PATH pollution that broke postCreate hooks\n\nImpact:\n- only affects track_mode=auto with remote-only branches
@ueryooo ueryooo requested a review from NatoBoram as a code owner December 6, 2025 09:52
@coderabbitai
Copy link

coderabbitai bot commented Dec 6, 2025

Walkthrough

The change modifies output redirection for git branch --track in lib/core.sh, shifting from stderr-only suppression (2>/dev/null) to full output redirection (>/dev/null 2>&1). This prevents stdout from the branch creation command from polluting the WORKTREE_PATH variable.

Changes

Cohort / File(s) Change Summary
Output redirection fix
lib/core.sh
Modified git branch --track command to redirect both stdout and stderr to /dev/null instead of stderr only, preventing output contamination of the returned worktree path.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • Single-line change affecting one file
  • Straightforward redirection pattern modification
  • Clear bug fix with no structural implications

Poem

🐰 The stdout was chatty, polluting the way,
So we hushed both its voices without delay.
Now WORKTREE_PATH flows clean and pure,
No cd confusion—the fix is secure! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: silencing branch track output when in auto mode, which directly addresses the bug fix in the changeset.
Linked Issues check ✅ Passed The code change directly implements the proposed fix from issue #32 by redirecting both stdout and stderr from git branch --track to /dev/null in auto mode, ensuring create_worktree returns only the worktree path.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to fixing the stdout pollution issue in lib/core.sh with no extraneous modifications; all changes are directly related to issue #32.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 15ec2e3 and d8e6b3b.

📒 Files selected for processing (1)
  • lib/core.sh (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
lib/**/*.sh

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

lib/**/*.sh: Core libraries (lib/core.sh, lib/config.sh, lib/ui.sh, lib/copy.sh, lib/hooks.sh, lib/platform.sh) must be sourced at startup and implement specific functionality
Maintain backwards compatibility with Git <2.22 by using fallback rev-parse --abbrev-ref HEAD instead of branch --show-current

lib/**/*.sh: Maintain backwards compatibility with existing configs in shell scripts
Quote all paths to support spaces in directory names
Use log_error / log_info from lib/ui.sh for user messages
Implement Git version fallbacks (e.g., Git 2.22+ --show-current vs older rev-parse); check lib/core.sh:97-100 for example
Add new config keys with gtr.<name> prefix to avoid collisions
For performance-sensitive loops (e.g., directory scans), prefer built-ins (find, grep) with minimal subshells
For any new Git command, add fallback for older versions or guard with detection

Files:

  • lib/core.sh
**/*.sh

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.sh: Always quote paths to handle spaces and special characters; avoid unguarded globbing
Keep set -e active in shell scripts; ensure non-critical failures are guarded with command || true

**/*.sh: Use shebang #!/usr/bin/env bash (not /bin/bash or /bin/sh) for all shell scripts
Use snake_case naming for functions and local variables, UPPER_CASE for constants and environment variables
Use 2-space indentation (no tabs) for all shell scripts
Always quote all variables and paths (e.g., "$var") in shell scripts
Check return codes and use || exit 1 or || return 1 for error handling in shell scripts

Files:

  • lib/core.sh
**/*.{bash,fish,sh}

📄 CodeRabbit inference engine (.github/instructions/sh.instructions.md)

**/*.{bash,fish,sh}: Bash 3.2+ compatible (macOS default), but 4.0+ features allowed where appropriate
Always quote variables: use "$var" not $var
Use function-scoped variables: local var="value"
Check return codes; functions return 1 on failure
Use snake_case for functions and variables, UPPER_CASE for constants
Prefer [ ] over [[ ]] for POSIX portability; use [[ only when needed
Always quote glob inputs; disable unintended globbing with set -f temporarily if required
Avoid associative arrays in shell scripts; use simple string/loop constructs for Bash 3.2+ compatibility
Avoid readarray and process substitution unsupported in older Bash
Debug with bash -x ./bin/gtr <cmd> or wrap suspicious blocks with set -x / set +x
Check function presence with declare -f create_worktree or declare -f resolve_target
Use stderr for variable inspection: echo "DEBUG var=$var" >&2 to keep stdout clean for command substitution
Keep dependencies minimal: only use git, sed, awk, find, grep; avoid jq/curl unless justified
Check availability of external commands before use when adding new tools
Use "${var}" for variable expansion; for line loops use while IFS= read -r line; do ... done to preserve spaces
Sanitize branch names via sanitize_branch_name function; do NOT duplicate logic elsewhere
Everything is sourced at startup with set -e enabled; functions call each other directly; no subshells except for hooks and AI tools

Files:

  • lib/core.sh
{bin/gtr,lib/**/*.sh,adapters/**/*.sh}

📄 CodeRabbit inference engine (.github/instructions/testing.instructions.md)

{bin/gtr,lib/**/*.sh,adapters/**/*.sh}: All commands must exit 0 (except intentional failures) and produce expected side-effects
No unquoted path errors; spaces must be handled in file paths
Hooks must run only once per creation/removal event

Files:

  • lib/core.sh
lib/*.sh

📄 CodeRabbit inference engine (CLAUDE.md)

lib/*.sh: Maintain backwards compatibility with existing configurations when modifying core functionality files
Follow POSIX-compatible Bash patterns targeting Bash 3.2+ in core library files
Use local for function-scoped variables in library files to prevent variable scope leakage
Provide clear error messages via log_error and log_info from lib/ui.sh in library files

Files:

  • lib/core.sh
🔇 Additional comments (1)
lib/core.sh (1)

378-378: Correctly silences stdout from intermediate git command.

The change from 2>/dev/null to >/dev/null 2>&1 properly suppresses both stdout and stderr from git branch --track, ensuring this intermediate step doesn't pollute the function's output. Since create_worktree is invoked as WORKTREE_PATH=$(create_worktree ...), any stdout from the tracking command would have been concatenated into the path variable, breaking downstream hooks. The fix is minimal and correct.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WORKTREE_PATH polluted when auto-creating remote-only branch (track_mode=auto)

1 participant