-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add configurable default worktree directory #24
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
The build/ directory is already in .gitignore and should not be tracked. Developers should run 'pnpm build' locally before using npm link. Build files will still be included in published npm packages via the 'files' field in package.json.
WalkthroughAdds a configurable global default worktree directory (set/get/clear) and uses it when creating new worktrees; removes compiled JavaScript build artifacts from the repository and updates README and .gitignore formatting. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant CLI
participant Config as Config Store
participant Cmd as Command Handler
participant Git
User->>CLI: config set worktreepath ~/worktrees
CLI->>Config: setDefaultWorktreePath("~/worktrees")
Config->>Config: expand "~", store absolute path
User->>CLI: new feat-xyz
CLI->>Cmd: newWorktreeHandler("feat-xyz")
Cmd->>Config: getDefaultWorktreePath()
alt defaultWorktreePath set
Config-->>Cmd: /home/alice/worktrees
Cmd->>Cmd: folder = /home/alice/worktrees/feat-xyz
else not set
Cmd->>Cmd: folder = ../repo-feat-xyz
end
Cmd->>Git: git worktree add <folder> ...
Git-->>Cmd: success
Cmd-->>CLI: open editor / done
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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 |
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
📒 Files selected for processing (18)
.gitignore(1 hunks)README.md(1 hunks)build/commands/config.js(0 hunks)build/commands/list.js(0 hunks)build/commands/merge.js(0 hunks)build/commands/new.js(0 hunks)build/commands/pr.js(0 hunks)build/commands/purge.js(0 hunks)build/commands/remove.js(0 hunks)build/config.js(0 hunks)build/index.js(0 hunks)build/utils/git.js(0 hunks)src/commands/config.ts(3 hunks)src/commands/new.ts(2 hunks)src/commands/pr.ts(2 hunks)src/commands/setup.ts(2 hunks)src/config.ts(3 hunks)src/index.ts(2 hunks)
💤 Files with no reviewable changes (10)
- build/commands/config.js
- build/commands/new.js
- build/config.js
- build/commands/purge.js
- build/index.js
- build/commands/list.js
- build/commands/pr.js
- build/commands/merge.js
- build/commands/remove.js
- build/utils/git.js
🧰 Additional context used
📓 Path-based instructions (3)
src/commands/new.ts
📄 CodeRabbit inference engine (.cursor/rules/project.mdc)
Implement logic for creating new Git worktrees, including options for branch creation, dependency installation, and opening in an editor, in src/commands/new.ts.
Files:
src/commands/new.ts
src/commands/*.ts
📄 CodeRabbit inference engine (.cursor/rules/project.mdc)
src/commands/*.ts: Leverage Execa to execute Git commands and other external processes.
Provide clear, colored console feedback for success and error messages in CLI commands.
Files:
src/commands/new.tssrc/commands/config.tssrc/commands/pr.tssrc/commands/setup.ts
src/index.ts
📄 CodeRabbit inference engine (.cursor/rules/project.mdc)
src/index.ts: The main entry point for the CLI is src/index.ts, which sets up CLI commands and orchestrates command handlers.
Utilize Commander for parsing CLI commands and handling options.
Files:
src/index.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
PR: johnlindquist/worktree-cli#0
File: .cursor/rules/project.mdc:0-0
Timestamp: 2025-08-04T13:02:29.847Z
Learning: Applies to src/commands/new.ts : Implement logic for creating new Git worktrees, including options for branch creation, dependency installation, and opening in an editor, in src/commands/new.ts.
📚 Learning: 2025-08-04T13:02:29.847Z
Learnt from: CR
PR: johnlindquist/worktree-cli#0
File: .cursor/rules/project.mdc:0-0
Timestamp: 2025-08-04T13:02:29.847Z
Learning: Applies to src/commands/new.ts : Implement logic for creating new Git worktrees, including options for branch creation, dependency installation, and opening in an editor, in src/commands/new.ts.
Applied to files:
src/commands/new.tssrc/commands/config.tssrc/commands/pr.tssrc/commands/setup.ts
📚 Learning: 2025-08-04T13:02:29.847Z
Learnt from: CR
PR: johnlindquist/worktree-cli#0
File: .cursor/rules/project.mdc:0-0
Timestamp: 2025-08-04T13:02:29.847Z
Learning: Applies to src/commands/remove.ts : Handle removal of Git worktrees, including support for force deletion, in src/commands/remove.ts.
Applied to files:
src/commands/new.tssrc/commands/config.tssrc/commands/pr.tssrc/commands/setup.ts
📚 Learning: 2025-08-04T13:02:29.847Z
Learnt from: CR
PR: johnlindquist/worktree-cli#0
File: .cursor/rules/project.mdc:0-0
Timestamp: 2025-08-04T13:02:29.847Z
Learning: Applies to src/commands/list.ts : Provide functionality to list existing Git worktrees in src/commands/list.ts.
Applied to files:
src/commands/new.tssrc/commands/config.tssrc/commands/pr.tssrc/commands/setup.ts
🧬 Code graph analysis (5)
src/commands/new.ts (1)
src/config.ts (1)
getDefaultWorktreePath(52-54)
src/commands/config.ts (1)
src/config.ts (4)
getDefaultEditor(37-39)getDefaultWorktreePath(52-54)setDefaultWorktreePath(57-63)clearDefaultWorktreePath(66-68)
src/index.ts (1)
src/commands/config.ts (1)
configHandler(4-67)
src/commands/pr.ts (1)
src/config.ts (1)
getDefaultWorktreePath(52-54)
src/commands/setup.ts (1)
src/config.ts (1)
getDefaultWorktreePath(52-54)
🔇 Additional comments (16)
.gitignore (1)
40-41: LGTM!The formatting change separating the comment from the pattern follows .gitignore best practices and improves readability.
README.md (1)
100-135: LGTM!The documentation is clear, comprehensive, and accurately describes the new feature with helpful examples and behavior comparisons.
src/commands/setup.ts (2)
6-6: LGTM!Import of
getDefaultWorktreePathcorrectly supports the new global worktree path feature.
37-47: LGTM!The path resolution logic correctly implements the documented priority:
--pathflag →defaultWorktreePathconfig → sibling directory fallback. The implementation is consistent with the same logic innew.tsandpr.ts.src/commands/new.ts (2)
5-5: LGTM!Import addition correctly supports the global worktree path feature.
36-46: LGTM!Path resolution logic correctly implements the priority:
--pathflag → global config → sibling directory fallback. Consistent withsetup.tsandpr.tsimplementations.As per coding guidelines.
src/commands/config.ts (5)
2-2: LGTM!Import additions correctly support the worktreepath configuration commands.
4-4: LGTM!Function signature correctly adds the
'clear'action to support clearing the worktreepath config.
11-17: LGTM!The get handler provides clear feedback whether a worktree path is configured or not, with helpful messaging about the fallback behavior.
30-36: LGTM!The set handler correctly saves the path and displays the resolved absolute path to the user, providing clear feedback about what value was stored.
46-54: LGTM!The clear handler provides appropriate feedback and correctly handles unknown configuration keys.
src/commands/pr.ts (2)
5-5: LGTM!Import addition correctly supports the global worktree path feature for PR worktrees.
119-129: LGTM!Path resolution correctly implements the documented priority with appropriate sanitization of the PR branch name for use in directory names.
src/index.ts (3)
157-176: LGTM!The
config setcommand group correctly adds theworktreepathsubcommand with appropriate description and action handler.As per coding guidelines.
186-190: LGTM!The
config getcommand correctly adds theworktreepathsubcommand with appropriate handler.As per coding guidelines.
192-200: LGTM!The new
config clearcommand group provides a clean way to reset the worktreepath configuration with clear user-facing description.As per coding guidelines.
- Add defaultWorktreePath config option - Add wt config set worktreepath <path> command - Add wt config get worktreepath command - Add wt config clear worktreepath command (reverts to sibling behavior) - Update new, setup, pr, and extract commands to use configured path - Support ~ expansion in path (expands to home directory) Path resolution priority: 1. --path flag (highest priority) 2. defaultWorktreePath config setting 3. Sibling directory behavior (default fallback) Example: wt config set worktreepath ~/worktrees wt new feature/login -> creates ~/worktrees/login Integrates PR #24 by @trevortrinh
|
Superseded by PR #30 which integrates this feature along with other fixes. Thank you for your contribution @trevortrinh! |
* fix: Address issues #27, #28, #29 - #27: Editor 'none' now skips opening editor instead of failing Added shouldSkipEditor() to config.ts and updated all command handlers to check for 'none' value before attempting to open editor - #28: wt new without branch name now shows clear error Added validation at start of newWorktreeHandler to require branch name - #29: build/index.js now has execute permissions after build Added postbuild script to package.json that runs chmod +x Also updated .gitignore to exclude .beads/ and .vscode/ directories * feat: Add GitLab support for pr command (PR #26) - Auto-detect git provider from remote URL (github.com or gitlab.com) - Add config option: wt config set provider gh|glab - Adapt pr command to work with both GitHub PRs and GitLab MRs - Update error messages to be provider-specific (PR vs MR, GitHub vs GitLab) - Add detectGitProvider function to git.ts - Add getGitProvider/setGitProvider to config.ts The tool automatically detects the provider from the remote URL. Manual configuration is available as fallback via config command. Backward compatible: defaults to gh (GitHub CLI) maintaining existing behavior. Integrates PR #26 by @Cl3MM * feat: Add configurable default worktree directory (PR #24) - Add defaultWorktreePath config option - Add wt config set worktreepath <path> command - Add wt config get worktreepath command - Add wt config clear worktreepath command (reverts to sibling behavior) - Update new, setup, pr, and extract commands to use configured path - Support ~ expansion in path (expands to home directory) Path resolution priority: 1. --path flag (highest priority) 2. defaultWorktreePath config setting 3. Sibling directory behavior (default fallback) Example: wt config set worktreepath ~/worktrees wt new feature/login -> creates ~/worktrees/login Integrates PR #24 by @trevortrinh * docs: Add JSDoc comments to key functions (PR #23) - Add detailed docstring to setupWorktreeHandler explaining parameters and behavior - Add docstring to isMainRepoBare function - Add docstring to getRepoRoot function Integrates documentation improvements from PR #23 by @coderabbitai * docs: Update README with new features - Document GitLab support for wt pr command - Document editor 'none' option to skip opening - Document git provider configuration - Document configurable default worktree directory - Update requirements section * feat: Add --setup flag to wt pr command (closes #25) - Create shared runSetupScripts utility in src/utils/setup.ts - Add -s, --setup option to pr command - Execute setup scripts from worktrees.json or .cursor/worktrees.json - Update README with --setup documentation This allows users to run setup scripts when creating a worktree from a PR/MR: wt pr 123 --setup * fix: Address CodeRabbit PR feedback - Fix GitLab MR branch lookup: use -o json instead of -F json - Add JSON parse error handling for clearer error messages - Improve GitLab detection: parse hostname properly instead of includes() - Fix magic string check: use hasWarnedAboutCheckout flag instead - Remove redundant default: undefined from config schema - Add HOME/USERPROFILE validation for tilde expansion - Make postbuild script cross-platform (works on Windows) - Add JSDoc documentation for detectGitProvider and getRemoteHostname
Summary
Adds a global configuration option to set a default directory where all worktrees will be created, instead of always creating sibling directories.
Changes
defaultWorktreePathconfig option with get/set/clear commandsnew,setup, andprcommands to use the global path when configured--path flag>defaultWorktreePathconfig > sibling directory (default)Usage
Example
Before (default):
wt new feature/login→/Users/me/projects/myrepo-loginAfter(with config):
wt new feature/login→~/Developer/.wt/loginAdditional
build/directory in .gitignoreSummary by CodeRabbit
New Features
Documentation