Repository navigation
fix: solve #4364 — case-insensitive branch lookup for workspace creation - #4367
Closed
github-actions[bot] wants to merge 1 commit into
Closed
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Branch names are case-sensitive in git, but the workspace-create input pathway routinely flattens user-typed casing (cmdk's lowercased selected value, OS autocaps, retyping a generated `claude/...-1UFT7` from memory). When the input case didn't match the canonical case stored in git, `planBranchSource` saw no match and silently forked a fresh branch from the base, so the next push opened a brand-new PR instead of continuing the existing one. Add a `resolveRefCaseInsensitive` fallback that scans `git for-each-ref` for a case-insensitive match (local wins over remote-tracking) and returns the canonical-cased ref. `planBranchSource` calls it after the exact-case `resolveRef` probe fails, before falling through to fresh- branch creation. Reproduced with a real bare-remote integration test in `workspace-create-delete.integration.test.ts`: the worktree's HEAD now points at the remote tip instead of the base branch's commit when the typed branch case doesn't match the remote's casing.
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.
Summary
When the user creates a workspace targeting an existing remote branch and the typed casing doesn't match the canonical casing in git (e.g. picker shows
claude/auto-balance-logo-sizing-1UFT7, but the value reaches the server as…-1uft7),planBranchSourcesilently forks a fresh branch frombaseBranchinstead of checking out the remote tip — and the next push opens a brand-new PR instead of continuing the existing one.Root cause
resolveRefprobesrefs/heads/<input>andrefs/remotes/origin/<input>viagit rev-parse --verify, which is case-sensitive on case-sensitive filesystems. Anything that flattens the user's casing on the way in (cmdk's lowercased selected value, OS autocaps, retyping from memory) misses the existing ref, soplanBranchSourcereturnsusedExistingBranch: falseand the worktree is created frommaininstead of the remote branch.The fix
Added
resolveRefCaseInsensitiveinpackages/host-service/src/runtime/git/refs.ts. It runsgit for-each-refoverrefs/heads/andrefs/remotes/origin/and returns the canonical-cased ref when an input matches case-insensitively (local match wins over remote-tracking).planBranchSourcecalls it after the exact-case probe fails, before falling through to fresh-branch creation. The plan'sbranchis set to the canonical case so the resulting local branch and the workspace row both store the same casing as the remote.Tests proving it
packages/host-service/test/integration/workspace-create-delete.integration.test.ts— two real-bare-remote scenarios:main. After the fix, it equals the remote tip.packages/host-service/src/runtime/git/refs.test.ts— 7 unit tests forresolveRefCaseInsensitive(canonical case, local-wins precedence,origin/fooshort-form,HEADskipped, empty input, no-match → null).Test plan
bun test packages/host-service/test/integration/workspace-create-delete.integration.test.ts— 12 passbun test packages/host-service/src/runtime/git/refs.test.ts— 19 passbun test packages/host-service/test/ packages/host-service/src/— 583 pass, 0 failbun run --filter @superset/host-service typecheck— cleanbun run lint— cleanCloses #4364
Summary by cubic
Fixes incorrect workspace creation when branch casing differs from the remote, so we continue the existing remote branch instead of forking from base. Addresses #4364.
resolveRefCaseInsensitiveto scan refs withgit for-each-refand return the canonical-cased match (local wins over remote; skipsorigin/HEAD; supportsorigin/fooinput).planBranchSourceto use this fallback afterresolveReffails and set the plan’sbranchto the canonical case, ensuring the worktree tracks the remote tip.Written for commit 0e15c7f. Summary will update on new commits.