-
Notifications
You must be signed in to change notification settings - Fork 59
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
Conversation
🚥 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 |
Prevent misleading next steps when --folder value matches the current branch name. In this case, the suggested commands would resolve to the main repo instead of the new worktree. Now falls back to using the branch name when a collision is detected.
Reject empty, ".", and ".." as folder names after sanitization. These could cause path issues or security concerns if allowed.
|
@helizaga I've added two fixes to address CR comments. |
Summary
--folderoption togit gtr newfor specifying custom folder namesCloses #81
Usage
Changes
bin/gtr: Add--folderflag parsing, validation, and help textbin/gtr: Add collision guard for next steps when--foldervalue matches current branchlib/core.sh: Addfolder_overrideparameter tocreate_worktree()lib/core.sh: Add validation to reject empty,., and..folder names (path traversal protection)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 otherwise--folder mainwhile onmainbranch shows branch name in next steps--folder "."rejected--folder ".."rejected--folder "///"(empty after sanitization) rejected--folder "..valid",--folder "valid.."work correctly--folder) still works--nameflag still worksSummary by CodeRabbit
New Features
Documentation
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.