feat: add --branch flag to wt step commit#1750
Conversation
Allows committing in a different worktree without changing directories: `wt step commit --branch feature-x` Adds `CommandEnv::for_branch()` which resolves the worktree path from a branch name. Updates `CommitOptions::commit()` to use the context's worktree path for all git operations instead of defaulting to cwd. Closes #1637 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
what happens on a detached worktree? |
|
A detached worktree can't be targeted with This is consistent with the project's model of addressing worktrees by branch name. If you're in a detached worktree, Should I add an explicit note about this in the help text, or is the current error message clear enough? |
ok great — would you mind confirming? |
|
I confirmed — my earlier claim was wrong. This is because So the full picture for detached worktrees:
Both are consistent with the worktree-by-branch model. If detached HEAD support for the cwd case is wanted, |
|
I think internally we should change to supply a worktree path, especially for the external interface would remain the same |
|
Makes sense — I'll rework |
…commit `for_action()` no longer requires a branch — it resolves the worktree path from cwd and populates the branch only when available. Commands that need a branch (merge, squash) already call `require_branch()` after construction. This makes `wt step commit` work in detached HEAD worktrees, since git only needs a worktree path to stage and commit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
src/cli/step.rs
Outdated
| /// Branch to operate on | ||
| /// | ||
| /// Defaults to current worktree. |
There was a problem hiding this comment.
Done — combined into /// Branch to operate on (defaults to current worktree).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
--branch/-bflag towt step commit, allowing commits in a different worktree withoutcd-ing there:wt step commit -b feature-xCommandEnv::for_branch()constructor that resolves a worktree path from a branch nameCommitOptions::commit()to use the context'sworktree_pathfor git operations (staging, status, commit) instead of hardcodingcurrent_worktree()— this makes it work correctly for both the default (cwd) and--branchcasesThis is the first step toward #1637. The
--branchflag can later be added to other step subcommands and eventually towt merge.Test plan
test_step_commit_branch_flag— commits to a feature worktree while cwd is the main worktree, verifies the commit lands in the correct worktreetest_step_commit_branch_flag_nonexistent— errors cleanly when the branch has no worktree🤖 Generated with Claude Code