Skip to content

feat(workspace): add worktree utility commands (root, move, lock, unlock, repair) - #20

Merged
reckerp merged 3 commits into
mainfrom
feat/workspace-utility-commands
Jun 29, 2026
Merged

feat(workspace): add worktree utility commands (root, move, lock, unlock, repair)#20
reckerp merged 3 commits into
mainfrom
feat/workspace-utility-commands

Conversation

@reckerp

@reckerp reckerp commented Jun 29, 2026

Copy link
Copy Markdown
Owner

What

Adds five worktree utility commands under the gx workspace namespace, implementing section 7 (Worktree Utility Commands) of the workspace improvement plan:

  • gx workspace root — prints the main worktree root on stdout, clean for scripts and aliases like cd "$(gx workspace root)".
  • gx workspace move <workspace> <new-path> — relocates a workspace via git worktree move. Refuses the main worktree and an existing destination; follows the shell wrapper into the new path when the current workspace is moved.
  • gx workspace lock <workspace> [--reason <reason>] — locks a worktree so cleanup and git worktree prune skip it. Refuses the main worktree.
  • gx workspace unlock <workspace> — clears a worktree lock.
  • gx workspace repair [workspace] — wraps git worktree repair for moved or damaged worktrees; repairs a single matched worktree, or all of them when no query is given.

Why

These useful git worktree operations were not discoverable through gx even though they fit naturally in the workspace namespace. lock/unlock in particular close a loop: gx already parses and displays locked state, so exposing the commands completes that feature.

How it works

  • Git helpers live in src/git/worktree.rs as thin wrappers around the matching git worktree subcommands. Each runs git from the main worktree root (where git requires worktree admin operations to run) and ends option parsing with -- so paths beginning with - are never treated as flags. Argument builders are split into pure functions for unit testing.
  • The move and lock/unlock/repair workspace arguments reuse the existing fuzzy workspace resolution (same matching as gx workspace go).
  • Safety: move refuses the main worktree and existing destinations; lock refuses the main worktree. Move-destination resolution expands ~ and makes relative paths absolute against the current directory via shared helpers (expand_home, resolve_dest_path), and expand_home is reused to de-duplicate the existing tilde-expansion logic in workspace_path.
  • All human-readable output goes to stderr, keeping stdout reserved for shell navigation. The single exception is root, whose entire purpose is to emit a path value on stdout.

Testing

  • cargo build — passes, no warnings.
  • cargo test — 136 tests pass, 0 failures. New tests cover the argument builders (move/lock with and without reason/unlock/repair forwarding paths) and the path helpers (expand_home, resolve_dest_path).
  • Modified files formatted with rustfmt.

reckerp added 3 commits June 29, 2026 21:47
Add thin wrappers around the corresponding `git worktree` subcommands in
src/git/worktree.rs. Each runs git from the main worktree root (where git
requires worktree administrative operations to run) and ends option parsing
with `--` so paths beginning with '-' are never treated as flags.

The argument builders are split into pure functions so they can be unit
tested without spawning git.
Expose worktree utility operations under the `gx workspace` namespace:

- `root` prints the main worktree root on stdout (clean for scripts and
  aliases like `cd "$(gx workspace root)"`).
- `move` relocates a workspace via `git worktree move`, reusing the same
  fuzzy matching as `gx workspace go`. It refuses the main worktree and an
  existing destination, and follows the shell wrapper into the new path
  when the current workspace is moved.
- `lock`/`unlock` expose git's worktree lock state, so locked worktrees are
  skipped by cleanup and `git worktree prune`. `lock` accepts an optional
  `--reason`.
- `repair` wraps `git worktree repair` for moved or damaged worktrees,
  repairing a single matched worktree or all of them when no query is given.

Human-readable output goes to stderr so stdout stays reserved for shell
navigation. Destructive/positional inputs resolve through shared helpers
(`expand_home`, `resolve_dest_path`) that expand `~` and make relative move
destinations absolute against the current directory.
Add the worktree utility commands to the workspace command reference in the
README so they are discoverable alongside the existing subcommands.
@reckerp
reckerp merged commit d5e85cd into main Jun 29, 2026
6 checks passed
@reckerp
reckerp deleted the feat/workspace-utility-commands branch June 29, 2026 20:37
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.

1 participant