Skip to content

Comments

fix: surface Git error message on worktree removal failure#55

Merged
helizaga merged 1 commit intomainfrom
fix/surface-git-remove-error
Dec 19, 2025
Merged

fix: surface Git error message on worktree removal failure#55
helizaga merged 1 commit intomainfrom
fix/surface-git-remove-error

Conversation

@helizaga
Copy link
Collaborator

@helizaga helizaga commented Dec 19, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages when worktree removal operations fail, providing better diagnostic information.

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

@helizaga helizaga requested a review from NatoBoram as a code owner December 19, 2025 22:27
@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

Walkthrough

The remove_worktree function in lib/core.sh was modified to capture the output of git worktree remove and leverage it for enhanced error logging. The function's public signature and success path remain unchanged; only internal logging behavior is updated.

Changes

Cohort / File(s) Change Summary
Error handling and logging enhancement
lib/core.sh
Modified remove_worktree function to capture git worktree remove output and use it to augment error logging with actual command output on failure, while maintaining success-path logging.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3–5 minutes

  • Single function modification with focused, localized changes to error handling and logging
  • No impact on public function signature or success path
  • No new dependencies or complex logic introduced

Poem

🐰 A worktree removed with care and grace,
Output captured, logged in place,
Errors whispered, loud and clear,
Debugging joy for all to hear! 🌟

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: improving error handling by surfacing Git error messages when worktree removal fails.
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
  • Commit unit tests in branch fix/surface-git-remove-error

📜 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 9eaa9f1 and b71a5d3.

📒 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 all functions and local variables in Bash scripts
Use UPPER_CASE naming for constants and environment variables in Bash scripts
Use 2-space indentation (no tabs) in all Bash scripts
Always quote variables and paths in Bash scripts (e.g., use "$var" not $var)
Check return codes and use || exit 1 or || return 1 for error handling in Bash scripts
Use local keyword for function-scoped variables in Bash scripts
Maintain POSIX-compatible Bash patterns targeting Bash 3.2+ compatibility
Git worktree operations must work cross-platform on macOS, Linux, and Windows Git Bash
All code must only use git and basic POSIX shell utilities - no external dependencies
Use set -e for error handling in Bash scripts where appropriate

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)

Library functions in lib/*.sh should maintain backwards compatibility with existing configurations

Files:

  • lib/core.sh
🧬 Code graph analysis (1)
lib/core.sh (1)
lib/ui.sh (2)
  • log_info (4-6)
  • log_error (12-14)
🔇 Additional comments (1)
lib/core.sh (1)

426-435: Excellent improvement to error reporting!

The implementation correctly captures Git's error output and surfaces it to users, which will provide much more actionable feedback when worktree removal fails (e.g., uncommitted changes, locked worktrees, etc.). The fallback to a generic message when output is empty is good defensive coding.


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

@helizaga helizaga merged commit 751a405 into main Dec 19, 2025
1 check passed
@helizaga helizaga deleted the fix/surface-git-remove-error branch December 19, 2025 22:30
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.

1 participant