Skip to content

docs(switch): trim upstream tracking, add missing hooks, combine PR/MR sections - #1521

Merged
max-sixty merged 8 commits into
mainfrom
fix/switch-docs-cleanup
Mar 14, 2026
Merged

max-sixty merged 8 commits into
mainfrom
fix/switch-docs-cleanup

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

  • Trimmed upstream tracking paragraph — --create doesn't configure upstream tracking, but that's standard git switch -c behavior. Removed the prominent explanation and folded the remote-branch note into the existing sentence.
  • Added missing hooks to creation lifecycle — The numbered list now includes pre-switch (step 1) and post-switch (step 6), matching the actual execution order in handle_switch.rs.
  • Combined GitHub/GitLab sections — Merged two near-identical sections into a single "Pull requests and merge requests" section, reducing repetition.

Closes #1518

Test plan

  • test_command_pages_and_skill_files_are_in_sync passes (docs auto-synced)
  • Unit tests pass
  • CI green

🤖 Generated with Claude Code

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs-only PR — changes are accurate and well-structured. Two minor observations:

Details

Hook lifecycle ordering: Steps 5 and 6 list post-start before post-switch, but the code prepares post-switch first, then extends with post-start before spawning both together. Since they're all background hooks spawned in a single batch, the ordering doesn't matter functionally — but step 6 says "Runs" while step 5 says "Spawns", which implies different execution modes. Both are background hooks, so consistent wording (both "Spawns" or both "Runs ... (background)") would be clearer.

Upstream tracking trimming: The removed paragraph about --create not configuring upstream tracking was useful context — it explained why git push -u is needed after creating a branch. The new single-sentence version is tighter but drops the actionable guidance. Worth considering whether a brief note like "use git push -u to set up tracking" would help users who hit that.

Both are minor — this is a nice cleanup overall.

Comment thread docs/content/switch.md Resolved
Comment thread docs/content/switch.md Resolved
Requires `gh` (GitHub) or `glab` (GitLab) CLI to be installed and authenticated. The `--create` flag cannot be used with `pr:`/`mr:` syntax since the branch already exists.

**Fork MRs:** The local branch uses the MR's branch name directly, so `git push` works normally. If a local branch with that name already exists tracking something else, rename it first.
**Forks:** The local branch uses the PR/MR's branch name directly (e.g., `feature-fix`), so `git push` works normally. If a local branch with that name already exists tracking something else, rename it first.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you confirm this is correct re requiring to rename it?

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit applied the suggestion to docs/content/switch.md but since src/cli/mod.rs is the primary source for command pages, the change needs to go there first — the sync test will propagate it to docs and skills. Currently src/cli/mod.rs and skills/worktrunk/reference/switch.md still have "— standard git behavior" while docs/content/switch.md doesn't.

On the two open questions:

"Spawns" vs "Runs" (line 48): Both post-start and post-switch are background hooks spawned in a single batch. The wording should be consistent — either both "Spawns" or both "Runs ... (background)".

Rename requirement (skills line 105): Verified — when a local branch exists but tracks a different ref, wt switch pr:N fails with BranchTracksDifferentRef and hints git branch -m. For GitHub, it also tries a prefixed name (pr-N/branch) as a fallback before erroring. So the docs are accurate — users do need to rename (or the prefixed fallback kicks in on GitHub only).

Comment thread src/cli/mod.rs Resolved
Comment thread docs/content/switch.md Resolved
@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot resolve conflicts

worktrunk-bot and others added 7 commits March 14, 2026 23:14
…R sections

- Remove verbose upstream tracking paragraph — `--create` matches
  standard git behavior (no upstream configured by default)
- Add pre-switch and post-switch hooks to worktree creation lifecycle
- Merge separate GitHub/GitLab sections into unified PR/MR section

Closes #1518

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: worktrunk-bot <[email protected]>
… source

The "Runs" → "Spawns" fix was applied to docs/content/switch.md but not
to src/cli/mod.rs (the primary source) or the snapshot. Both post-start
and post-switch are background hooks spawned in the same batch.

Co-Authored-By: Claude <[email protected]>
@worktrunk-bot
worktrunk-bot force-pushed the fix/switch-docs-cleanup branch from 8c05f97 to 5c0dd4b Compare March 14, 2026 23:16

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale snapshot: src/cli/mod.rs no longer has "— standard git behavior" but the snapshot still does. The snapshot test will fail — regenerate with cargo test --test integration help_switch_long and commit the updated snapshot.

Previous feedback (rename requirement, "Spawns" wording) is addressed — both look good now.

The snapshot had "— standard git behavior" suffix from a review
suggestion applied to docs but not the primary source in cli.rs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@max-sixty
max-sixty enabled auto-merge (squash) March 14, 2026 23:31
@max-sixty
max-sixty merged commit df54d28 into main Mar 14, 2026
20 checks passed
@max-sixty
max-sixty deleted the fix/switch-docs-cleanup branch March 14, 2026 23:31
@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Rebased onto main to resolve conflicts with #1523 (experimental badge anchor changes). Also fixed a stale snapshot — help_switch_long had — standard git behavior trailing text that didn't match the primary source in src/cli/mod.rs.

All CI checks pass.

max-sixty pushed a commit that referenced this pull request Mar 14, 2026
## Summary

- Add `INSTA_UPDATE=always cargo test ... "test_help"` guidance to both
CLAUDE.md and tests/CLAUDE.md for updating help snapshots after editing
`after_long_help` text
- Add a note to never manually edit `.snap` files (they contain ANSI
escape sequences)

## Evidence

In run
[23096056615](https://github.com/max-sixty/worktrunk/actions/runs/23096056615),
the mention bot edited `after_long_help` in `src/cli/mod.rs` for PR
#1521 but only ran `cargo test --lib --bins` before pushing. The
`help_switch_long` snapshot test failed in CI, requiring a second
commit.

The bot then struggled through 7 approaches to update the snapshot:
1. `cargo insta test --accept` (didn't work for file-based snapshots in
this context)
2. Manual inspection of the snapshot file with `sed`
3. `cat -A` to examine raw bytes
4. Manual `Edit` of the snapshot file (couldn't reproduce ANSI escapes)
5. Trying to regenerate help output and compare
6. `UPDATE_SNAPSHOTS=1` (wrong env var name)
7. `INSTA_UPDATE=always` (correct — finally worked)

The `tests/CLAUDE.md` only mentioned `cargo insta test --accept` for
*first-time* inline snapshot creation. There was no guidance for
updating existing file-based snapshots, and CLAUDE.md didn't mention the
need to update help snapshots after editing help text.

## Test plan

- [ ] Verify the new guidance is clear and actionable
- [ ] Confirm `INSTA_UPDATE=always cargo test --test integration
"test_help"` works as documented

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
worktrunk-bot added a commit that referenced this pull request Mar 15, 2026
Two behavioral issues observed in the past hour's CI runs:

1. Triple approval on PR #1531 — each of 3 commits triggered a new review
   run, and each re-approved despite the prior approval covering the same
   PR. The trivial-change exit path said "skip steps 2-3" but didn't
   explicitly block step 4 (approval), so the bot re-approved on trivial
   incremental changes.

2. Self-approval attempts on PRs #1521 and #1529 — the bot attempted
   `gh pr review --approve` on its own PRs before discovering GitHub
   rejects self-approvals. The authorship check was buried in step 4
   instead of being caught in pre-flight.

Fixes:
- Add IS_SELF_AUTHORED check to pre-flight (step 1) so the bot knows
  before reaching step 4
- Make trivial-change exit path explicitly skip steps 2, 3, AND 4
- Update step 4 self-authored guidance to reference the pre-flight flag

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.

switch docs

2 participants