-
Notifications
You must be signed in to change notification settings - Fork 222
fix: clear error when new branch name collides with existing branch namespace #3528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
53 changes: 53 additions & 0 deletions
53
...s/snapshots/integration__integration_tests__switch__switch_create_namespace_conflict.snap
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --- | ||
| source: tests/integration_tests/switch.rs | ||
| info: | ||
| program: wt | ||
| args: | ||
| - switch | ||
| - "--create" | ||
| - release | ||
| env: | ||
| APPDATA: "[TEST_CONFIG_HOME]" | ||
| CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]" | ||
| CLICOLOR_FORCE: "1" | ||
| COLUMNS: "500" | ||
| GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z" | ||
| GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z" | ||
| GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]" | ||
| GIT_CONFIG_SYSTEM: /dev/null | ||
| GIT_TERMINAL_PROMPT: "0" | ||
| HOME: "[TEST_HOME]" | ||
| LANG: C | ||
| LC_ALL: C | ||
| LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]" | ||
| MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]" | ||
| OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]" | ||
| PATH: "[PATH]" | ||
| TERM: alacritty | ||
| USERPROFILE: "[TEST_HOME]" | ||
| WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]" | ||
| WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]" | ||
| WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]" | ||
| WORKTRUNK_TEST_BASH_INSTALLED: "0" | ||
| WORKTRUNK_TEST_CLAUDE_INSTALLED: "0" | ||
| WORKTRUNK_TEST_CODEX_INSTALLED: "0" | ||
| WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1" | ||
| WORKTRUNK_TEST_EPOCH: "1735776000" | ||
| WORKTRUNK_TEST_FISH_INSTALLED: "0" | ||
| WORKTRUNK_TEST_GEMINI_INSTALLED: "0" | ||
| WORKTRUNK_TEST_NUSHELL_ENV: "0" | ||
| WORKTRUNK_TEST_OPENCODE_INSTALLED: "0" | ||
| WORKTRUNK_TEST_PARENT_SHELL: "" | ||
| WORKTRUNK_TEST_POWERSHELL_ENV: "0" | ||
| WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0" | ||
| WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1" | ||
| WORKTRUNK_TEST_ZSH_INSTALLED: "0" | ||
| XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]" | ||
| --- | ||
| success: false | ||
| exit_code: 1 | ||
| ----- stdout ----- | ||
|
|
||
| ----- stderr ----- | ||
| [31m✗[39m [31mCannot create branch [1mrelease[22m — it collides with existing branch [1mrelease/2026.4[22m[39m | ||
| [2m↳[22m [2mGit stores branches as file paths, so [4mrelease[24m and [4mrelease/2026.4[24m can't both exist. Pick a different name, or rename the existing branch.[22m |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: this fires on any
git worktree addfailure once a colliding branch exists, so it can mask an unrelated cause with the namespace message. E.g.wt switch --create release --from badrefwhenrelease/2026.4exists — git actually failed on the invalid base ref, but we'd report the namespace collision and swallowinvalid reference: badref. The path-occupancy and non-create checks are already guarded earlier invalidate_worktree_creation, so the realistic remaining case is a bad--from. Narrow, and the reported message is still a real problem the user would hit next, so not blocking — just flagging the unconditional swap of git's error. Could tighten by only substituting when the collision is the plausible cause, but that risks re-introducing error-text parsing, so the current tradeoff may well be the right call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good flag — I chased down whether the misattribution can actually happen, and for the
--basecase it can't:--create --base <ref>resolves and validates the base withref_exists()up front at switch.rs:605, so an invalid base errors withReferenceNotFoundbeforegit worktree addever runs. Verified end-to-end —wt switch --create release --base badrefwithrelease/2026.4present reports✗ No branch, tag, or commit named badref, not the namespace collision.So by the time we reach the failing
git worktree add: the path is pre-checked invalidate_worktree_creation, the base is either a validated ref orNone(→HEAD, always valid), and--createis set. The only inputs left that can fail there are the D/F collision itself plus rare environmental/race failures — and in the environmental case the swap only fires if a colliding branch also exists, where the namespace conflict is a genuine latent blocker anyway.I did prototype the tightening you suggested — gate the swap on
base_branch.as_deref().is_none_or(|b| repo.ref_exists(b)...)— but since the base is already validated at line 605, its false branch is structurally unreachable, so it'd be speculative dead code (and would tripcodecov/patch). Dropped it. The unconditional swap is the right call here; leaving it as-is.