-
Notifications
You must be signed in to change notification settings - Fork 39
feat: add .worktreeinclude file support #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughAdds support for a repository-root Changes
Sequence DiagramsequenceDiagram
autonumber
participant GTR as bin/gtr
participant PARSE as lib/copy.sh:parse_pattern_file()
participant FILE as repo_root/.worktreeinclude
participant MERGE as Merge Logic
GTR->>PARSE: call parse_pattern_file(repo_root/.worktreeinclude)
PARSE->>FILE: attempt to read file
alt file exists
PARSE->>PARSE: remove lines starting with '#' and blank lines
PARSE-->>GTR: return newline-separated patterns
else file missing
PARSE-->>GTR: return empty / success
end
GTR->>MERGE: provide file_includes + gtr.copy.include (if skip_copy=0)
MERGE->>MERGE: concatenate newline-separated lists
MERGE-->>GTR: merged includes used for copying
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
CLAUDE.md (1)
136-143: Replaceecho -ewithprintffor better portability.The
echo -eflag is not POSIX-compliant and behaves differently across shells. Useprintffor reliable newline handling.Apply this diff:
# Test .worktreeinclude file -echo -e "# Test patterns\n**/.env.example\n*.md" > .worktreeinclude +printf "# Test patterns\n**/.env.example\n*.md\n" > .worktreeinclude echo "TEST=value" > .env.example ./bin/gtr new test-worktreeincludeREADME.md (2)
375-382: Add language specifier to fenced code block.The fenced code block should specify a language for syntax highlighting and clarity. Since this represents the content of a
.worktreeincludefile (gitignore-style), usegitignoreortext.Apply this diff:
Alternatively, create a `.worktreeinclude` file in your repository root: -``` +```gitignore # .worktreeinclude - files to copy to new worktrees # Comments start with #Based on static analysis hints.
371-384: Consider documenting that.worktreeincludeshould be committed to the repository.The documentation describes the feature well, but it might be helpful to explicitly mention that the
.worktreeincludefile should be committed to version control so the patterns are shared across the team (similar to.gitignore). This aligns with the PR motivation of enabling pattern sharing instead of per-developer configuration.
📜 Review details
Configuration used: CodeRabbit UI
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.
📒 Files selected for processing (4)
CLAUDE.md(2 hunks)README.md(1 hunks)bin/gtr(1 hunks)lib/copy.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 fallbackrev-parse --abbrev-ref HEADinstead ofbranch --show-current
lib/**/*.sh: Maintain backwards compatibility with existing configs in shell scripts
Quote all paths to support spaces in directory names
Uselog_error/log_infofromlib/ui.shfor user messages
Implement Git version fallbacks (e.g., Git 2.22+--show-currentvs olderrev-parse); checklib/core.sh:97-100for example
Add new config keys withgtr.<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/copy.sh
**/*.sh
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.sh: Always quote paths to handle spaces and special characters; avoid unguarded globbing
Keepset -eactive in shell scripts; ensure non-critical failures are guarded withcommand || true
**/*.sh: Use shebang#!/usr/bin/env bash(not/bin/bashor/bin/sh)
Use snake_case naming for functions
Use snake_case for local variables and UPPER_CASE for constants/environment variables
Use 2-space indentation (no tabs) in Bash scripts
Always quote variables and paths in Bash scripts
Check return codes and use|| exit 1or|| return 1for error handling
Files:
lib/copy.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
Usesnake_casefor functions and variables,UPPER_CASEfor constants
Prefer[ ]over[[ ]]for POSIX portability; use[[only when needed
Always quote glob inputs; disable unintended globbing withset -ftemporarily if required
Avoid associative arrays in shell scripts; use simple string/loop constructs for Bash 3.2+ compatibility
Avoidreadarrayand process substitution unsupported in older Bash
Debug withbash -x ./bin/gtr <cmd>or wrap suspicious blocks withset -x/set +x
Check function presence withdeclare -f create_worktreeordeclare -f resolve_target
Use stderr for variable inspection:echo "DEBUG var=$var" >&2to keep stdout clean for command substitution
Keep dependencies minimal: only usegit,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 usewhile IFS= read -r line; do ... doneto preserve spaces
Sanitize branch names viasanitize_branch_namefunction; do NOT duplicate logic elsewhere
Everything is sourced at startup withset -eenabled; functions call each other directly; no subshells except for hooks and AI tools
Files:
lib/copy.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/copy.shbin/gtr
bin/gtr
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
bin/gtr: Dispatch commands throughcmd_*functions inbin/gtr(case block lines 36‑77)
UpdateGTR_VERSIONon line 8 ofbin/gtrwhen releasing; this affectsgtr version/--versionoutputGlobal
set -einbin/gtr: guard non-critical commands with|| true
list --porcelainoutput must remain stable for scripting purposesUpdate GTR_VERSION constant at line 8 when releasing a new version
Files:
bin/gtr
🪛 markdownlint-cli2 (0.18.1)
README.md
375-375: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🔇 Additional comments (3)
CLAUDE.md (1)
414-414: LGTM!Documentation accurately describes the new
.worktreeincludeconfiguration key and its relationship togtr.copy.include.bin/gtr (1)
247-257: LGTM! Clean integration of.worktreeincludesupport.The implementation correctly:
- Reads patterns from the repo root
.worktreeincludefile usingparse_pattern_file- Handles the case where the file doesn't exist (graceful fallback)
- Merges patterns with existing
gtr.copy.includeconfiguration- Preserves existing behavior when only one source is present
- Only activates when copying is enabled (
skip_copy=0)The patterns will go through the same security validation in
copy_patternsas configured patterns.lib/copy.sh (1)
4-16: LGTM! Robust pattern file parsing with proper error handling.The function correctly:
- Returns gracefully (exit 0) when the file doesn't exist, making
.worktreeincludeoptional- Strips comment lines (starting with
#) and blank lines using POSIX-compliantgrep- Handles all edge cases (empty file, only comments, only blanks) through the
|| trueguard- Follows coding guidelines: local variables, proper quoting, and compatible with
set -eThe implementation aligns with
.gitignore-style syntax as documented.
CLAUDE.md
Outdated
| # Expected: Copies .env.example but not .env | ||
|
|
||
| # Test .worktreeinclude file | ||
| echo -e "# Test patterns\n**/.env.example\n*.md" > .worktreeinclude |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo -e → printf for POSIX compatibility
|
LGTM just fix nitpick |
Add support for reading glob patterns from a `.worktreeinclude` file in the repository root, similar to Claude Code's implementation. This feature allows users to commit file copy patterns to the repository instead of requiring each developer to configure `gtr.copy.include` manually. Features: - `.gitignore`-style syntax (# for comments, empty lines ignored) - Patterns are merged with `gtr.copy.include` config (both sources used) - File is optional - missing file is silently ignored Implementation: - Add `parse_pattern_file()` function in lib/copy.sh - Read and merge patterns in cmd_create() in bin/gtr 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Replace echo -e with printf in the .worktreeinclude test example to ensure compatibility with POSIX shells that don't support the -e flag. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1a0664e to
126641f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
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.
📒 Files selected for processing (4)
CLAUDE.md(2 hunks)README.md(1 hunks)bin/gtr(1 hunks)lib/copy.sh(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- CLAUDE.md
- lib/copy.sh
🧰 Additional context used
📓 Path-based instructions (2)
bin/gtr
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
bin/gtr: Dispatch commands throughcmd_*functions inbin/gtr(case block lines 36‑77)
UpdateGTR_VERSIONon line 8 ofbin/gtrwhen releasing; this affectsgtr version/--versionoutputGlobal
set -einbin/gtr: guard non-critical commands with|| true
list --porcelainoutput must remain stable for scripting purposesUpdate GTR_VERSION constant at line 8 when releasing a new version
Files:
bin/gtr
{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:
bin/gtr
🪛 markdownlint-cli2 (0.18.1)
README.md
376-376: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🔇 Additional comments (2)
bin/gtr (2)
243-243: LGTM - Variable declaration is clear.Adding
file_includesto the local variable declaration properly scopes it for the pattern merging logic.
247-257: Verify error handling for missing or inaccessible .worktreeinclude file.The merge logic correctly concatenates patterns with newline separation. However, the
parse_pattern_filecall is not guarded against errors. If the file is inaccessible (e.g., permission denied), the script will exit due toset -e. Per coding guidelines, non-critical commands should be guarded with|| true. Verify thatparse_pattern_filehandles all error cases gracefully (returns empty string for missing/inaccessible files) or add error handling. Additionally, ensure$file_includesis quoted to handle spaces in file paths:includes="$includes"$'\n'"$file_includes"→includes="$includes"$'\n'"$file_includes".
Add gitignore language specifier to the .worktreeinclude example code block for proper syntax highlighting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Description
Add support for reading glob patterns from a
.worktreeincludefile in the repository root.This implementation follows Claude Code's
.worktreeincludeapproach, allowing users to commit file copy patterns to the repository instead of requiring each developer to configuregtr.copy.includemanually.Reference: https://code.claude.com/docs/en/desktop
Motivation
Currently, file copy patterns must be configured per-developer using
git gtr config add gtr.copy.include. This means:With
.worktreeinclude, teams can define standard patterns in the repository, similar to how.gitignoreworks.Type of Change
Testing
Manual Testing Checklist
Tested on:
Core functionality tested:
git gtr new <branch>- Create worktreegit gtr go <branch>- Navigate to worktreegit gtr editor <branch>- Open in editor (if applicable)git gtr ai <branch>- Start AI tool (if applicable)git gtr rm <branch>- Remove worktreegit gtr list- List worktreesgit gtr config- Configuration commands (if applicable)Test Steps
.worktreeincludefile:echo "TEST=value" > .env.example./bin/gtr new test-worktreeincludels "$(./bin/gtr go test-worktreeinclude)/.env.example"./bin/gtr rm test-worktreeinclude && rm .worktreeinclude .env.exampleExpected behavior: Files matching patterns in
.worktreeincludeare copied to the new worktree.Actual behavior: Files are copied as expected. Patterns from
.worktreeincludeare merged withgtr.copy.includeconfig.Breaking Changes
Checklist
Before submitting this PR, please check:
git gtr(production) and./bin/gtr(development)Additional Context
Implementation Details
lib/copy.sh: Addedparse_pattern_file()function that reads a file and strips comments (#) and empty lines, returning newline-separated patterns.bin/gtr: Modifiedcmd_create()to read.worktreeincludeand merge its patterns withgtr.copy.includeconfig.File Format
The
.worktreeincludefile uses.gitignore-style syntax:#are commentsLicense Acknowledgment
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.