feat(workspace): add worktree utility commands (root, move, lock, unlock, repair) - #20
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds five worktree utility commands under the
gx workspacenamespace, 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 likecd "$(gx workspace root)".gx workspace move <workspace> <new-path>— relocates a workspace viagit 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 andgit worktree pruneskip it. Refuses the main worktree.gx workspace unlock <workspace>— clears a worktree lock.gx workspace repair [workspace]— wrapsgit worktree repairfor moved or damaged worktrees; repairs a single matched worktree, or all of them when no query is given.Why
These useful
git worktreeoperations were not discoverable throughgxeven though they fit naturally in the workspace namespace.lock/unlockin particular close a loop:gxalready parses and displays locked state, so exposing the commands completes that feature.How it works
src/git/worktree.rsas thin wrappers around the matchinggit worktreesubcommands. 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.moveandlock/unlock/repairworkspace arguments reuse the existing fuzzy workspace resolution (same matching asgx workspace go).moverefuses the main worktree and existing destinations;lockrefuses the main worktree. Move-destination resolution expands~and makes relative paths absolute against the current directory via shared helpers (expand_home,resolve_dest_path), andexpand_homeis reused to de-duplicate the existing tilde-expansion logic inworkspace_path.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/lockwith and without reason/unlock/repairforwarding paths) and the path helpers (expand_home,resolve_dest_path).