Skip to content

Conversation

@trevortrinh
Copy link

@trevortrinh trevortrinh commented Oct 28, 2025

Summary

Adds a global configuration option to set a default directory where all worktrees will be created, instead of always creating sibling directories.

Changes

  • Added defaultWorktreePath config option with get/set/clear commands
  • Updated path resolution logic in new, setup, and pr commands to use the global path when configured
  • Path resolution priority: --path flag > defaultWorktreePath config > sibling directory (default)

Usage

# Set default worktree directory
wt config set worktreepath ~/Developer/.wt

# Get current setting
wt config get worktreepath

# Clear setting (revert to sibling directory behavior)
wt config clear worktreepath

Example

Before (default): wt new feature/login/Users/me/projects/myrepo-loginAfter
(with config): wt new feature/login~/Developer/.wt/login

Additional

  • Fix build/ directory in .gitignore

Summary by CodeRabbit

  • New Features

    • Added config commands to set/get/clear a global default worktree directory; new worktrees (new/pr/setup flows) use this directory when configured.
  • Documentation

    • README updated with usage, examples, and path resolution priority for the default worktree directory.

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.
@coderabbitai
Copy link

coderabbitai bot commented Oct 28, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Removed build artifacts
build/...
Deleted compiled JS build output: CLI entry, command handlers, config, and git utilities under build/ (commands: config.js, list.js, merge.js, new.js, pr.js, purge.js, remove.js; plus index.js, config.js, utils/git.js).
Config API expansion
src/config.ts
Added defaultWorktreePath?: string to schema and three new APIs: getDefaultWorktreePath(), setDefaultWorktreePath(path), clearDefaultWorktreePath() with tilde-expansion/absolute resolution.
CLI config command updates
src/commands/config.ts, src/index.ts
Extended configHandler and CLI to support worktreepath key and clear action. Added subcommands: config set worktreepath <path>, config get worktreepath, config clear worktreepath.
Worktree path resolution changes
src/commands/new.ts, src/commands/pr.ts, src/commands/setup.ts
When configured, new/pr/setup commands now place worktrees under the global defaultWorktreePath (subdir by branch name); otherwise fall back to previous sibling-directory pattern. PR flow adds a main-worktree cleanliness pre-check.
Docs & misc
.gitignore, README.md
.gitignore comment separated from pattern; README extended with "Configure Default Worktree Directory" docs and examples.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas to inspect:
    • Path resolution and tilde expansion in src/config.ts (setDefaultWorktreePath)
    • Consistent fallback behavior across src/commands/new.ts, src/commands/pr.ts, src/commands/setup.ts
    • src/commands/config.ts handling of clear action
    • CLI wiring in src/index.ts
    • Ensure removals under build/ don't leave consumers expecting those modules

Possibly related PRs

Poem

🐰 I hopped through code and left a trail,
A default path to catch each tail.
From config set to worktree bloom,
New branches find a cozy room.
Hooray—more places to explore! 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat: add configurable default worktree directory" accurately and concisely summarizes the primary objective of this changeset. The main changes introduce a new defaultWorktreePath config option with associated getter, setter, and clearer functions in src/config.ts, extend the CLI commands in src/index.ts to expose get/set/clear subcommands for this config, and update the path resolution logic in src/commands/new.ts, src/commands/pr.ts, and src/commands/setup.ts to use the configured default path. The title is clear, specific, and appropriately conveys the core feature being added without extraneous details or vague phrasing.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4837889 and c52a247.

📒 Files selected for processing (1)
  • src/config.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/config.ts

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.

❤️ Share

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

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between e1d95fe and 4837889.

📒 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.ts
  • src/commands/config.ts
  • src/commands/pr.ts
  • src/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.ts
  • src/commands/config.ts
  • src/commands/pr.ts
  • src/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.ts
  • src/commands/config.ts
  • src/commands/pr.ts
  • src/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.ts
  • src/commands/config.ts
  • src/commands/pr.ts
  • src/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 getDefaultWorktreePath correctly supports the new global worktree path feature.


37-47: LGTM!

The path resolution logic correctly implements the documented priority: --path flag → defaultWorktreePath config → sibling directory fallback. The implementation is consistent with the same logic in new.ts and pr.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: --path flag → global config → sibling directory fallback. Consistent with setup.ts and pr.ts implementations.

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 set command group correctly adds the worktreepath subcommand with appropriate description and action handler.

As per coding guidelines.


186-190: LGTM!

The config get command correctly adds the worktreepath subcommand with appropriate handler.

As per coding guidelines.


192-200: LGTM!

The new config clear command group provides a clean way to reset the worktreepath configuration with clear user-facing description.

As per coding guidelines.

johnlindquist added a commit that referenced this pull request Dec 7, 2025
- 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
@johnlindquist
Copy link
Owner

Superseded by PR #30 which integrates this feature along with other fixes. Thank you for your contribution @trevortrinh!

johnlindquist added a commit that referenced this pull request Dec 7, 2025
* 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
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.

2 participants