-
Notifications
You must be signed in to change notification settings - Fork 57
feat: add --folder flag for custom worktree folder names #82
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
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughAdds a new --folder flag to git gtr new to specify a custom worktree folder name (sanitized). The flag is mutually exclusive with --name, is accepted by --force, updates folder-name construction in create_worktree, and updates documentation and shell completions. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI as bin/gtr
participant Core as lib/core.sh
participant GitFS as Git/Filesystem
User->>CLI: git gtr new <branch> --folder <name> [--force]
CLI->>CLI: parse flags, validate (--folder xor --name), allow --force with folder
CLI->>Core: call create_worktree(base_dir, repo, branch, ... , custom_name, folder_override)
Core->>Core: sanitize folder_override (if present) -> determine folder_name
Core->>GitFS: create worktree at <base_dir>/<folder_name>
GitFS-->>Core: success / error
Core-->>CLI: result + effective identifier (folder_name or branch)
CLI-->>User: display next steps referencing effective identifier
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
1eefcb5 to
b90cf72
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
🤖 Fix all issues with AI agents
In `@bin/gtr`:
- Around line 353-367: When computing next_steps_id for displayed commands
(variables: next_steps_id, folder_override, folder_name, branch_name), add a
collision guard so that if folder_override is set but the resolved target (use
resolve_target) would point to the main repo or otherwise equals the current
branch_name, fall back to using branch_name (or include both identifiers)
instead of folder_name; update the logic that builds next_steps_id and the
subsequent echo lines for the git gtr editor/ai/go suggestions to use the safe
identifier so the suggested commands don't accidentally reference the main repo.
Allow specifying a custom folder name with --folder when creating worktrees, decoupling the folder name from the branch name. Useful for long branch names that would create unwieldy folder names. Closes coderabbitai#81
96b691f to
6b4f5c5
Compare
6b4f5c5 to
b1b8709
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/core.sh (1)
293-300: Validate--folderagainst empty / “.” / “..” to prevent base-dir escape.
Sanitization doesn’t block “.” or “..”; those values would resolve to the base dir or its parent. Add a guard after computingsanitized_name.🛠️ Proposed fix
if [ -n "$folder_override" ]; then sanitized_name=$(sanitize_branch_name "$folder_override") elif [ -n "$custom_name" ]; then sanitized_name="$(sanitize_branch_name "$branch_name")-${custom_name}" else sanitized_name=$(sanitize_branch_name "$branch_name") fi + + if [ -z "$sanitized_name" ] || [ "$sanitized_name" = "." ] || [ "$sanitized_name" = ".." ]; then + if [ -n "$folder_override" ]; then + log_error "Invalid --folder value: $folder_override" + else + log_error "Invalid worktree folder name derived from branch: $branch_name" + fi + return 1 + fi
♻️ Duplicate comments (1)
bin/gtr (1)
353-367: Next-steps identifier can still collide with current branch name.
Same concern as earlier: if--foldermatches the repo’s current branch, the suggested commands target the main repo instead of the new worktree.
|
looks goodl! nit: folder main while on main branch causes git gtr go main to resolve to the main repo instead of the worktree. might want that collision guard CR suggested |
Summary
--folderoption togit gtr newfor specifying custom folder namesCloses #81
Usage
Changes
bin/gtr: Add--folderflag parsing, validation, and help textlib/core.sh: Addfolder_overrideparameter tocreate_worktree()completions/: Add--folderto bash, zsh, and fish completionsREADME.md: Document--folderoption with examplesTesting performed
--folderusage creates correct folder--folderand--namemutual exclusivity error--forcerequires--nameor--foldererror--forcewith--folderworks--folderoption--folder, branch name otherwiseSummary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.