Skip to content

Fix branch selector confusion during merge/rebase conflicts#2017

Draft
posthog[bot] wants to merge 1 commit intomainfrom
posthog-code/fix-branch-selector-during-merge-conflict
Draft

Fix branch selector confusion during merge/rebase conflicts#2017
posthog[bot] wants to merge 1 commit intomainfrom
posthog-code/fix-branch-selector-during-merge-conflict

Conversation

@posthog
Copy link
Copy Markdown
Contributor

@posthog posthog Bot commented May 4, 2026

Summary

When the local repo is mid-rebase (or merge/cherry-pick/revert), the new task input's branch selector behaved badly in three ways. This PR cleans all three up.

# Symptom Cause Fix
1 First dropdown item was literally (no simple-git's branchLocal() parser greedily mis-parses git's * (no branch, rebasing main) pseudo-branch line and returns (no as a "branch name" Switched getAllBranches to git for-each-ref refs/heads/ so only real branches are returned
2 Label said "No branch" with no explanation getCurrentBranch returns null during rebase (HEAD is detached on the rebase pseudo-ref) New getGitBusyState tRPC query reports rebase/merge/cherry-pick/revert; the selector now shows "Rebasing", "Merging", etc. when there's no current branch
3 Picking a branch threw Failed to checkout … git refuses checkout while an operation is in progress The selector is disabled in local mode when busy, with a tooltip: "Rebasing in progress — finish or abort it to switch branches."

The busy-state probe (rebase-merge/, MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD) was already implemented inside CaptureCheckpointSaga. It's now extracted to inspectGitBusyState in queries.ts so the saga and the new public getGitBusyState(baseDir) share one implementation — no behavior change for the saga; existing 18 checkpoint tests still pass.

Worktree and cloud modes are unaffected (busyState only applies when !isSelectionOnly).

Test plan

  • New unit test covers getAllBranches filtering the (no pseudo-branch during a rebase conflict
  • New unit test covers getGitBusyState reporting { busy: true, operation: "rebase" } mid-rebase
  • All 18 existing checkpoint sagas tests still pass after extracting inspectGitBusyState
  • Manually verify in dev: open new task input while local repo is mid-rebase → selector shows "Rebasing" and is disabled with tooltip; dropdown contains only real branches

Created with PostHog Code

When a repo is mid-rebase (or merge/cherry-pick/revert), the new task input's
branch selector showed three confusing things:

1. The first item in the dropdown was `(no` — simple-git's `branchLocal()`
   parser misreads git's `(no branch, rebasing main)` pseudo-branch line.
   Switched `getAllBranches` to `git for-each-ref refs/heads/`, which only
   returns real local branches.
2. The label said "No branch" with no hint that an operation was in progress.
   Added a `getGitBusyState` query that exposes rebase/merge/cherry-pick/revert
   state, and the selector now shows "Rebasing", "Merging", etc. when there
   is no current branch.
3. Selecting a branch threw a checkout error because git refuses checkout
   while a working-tree operation is in progress. The selector is now disabled
   in local mode while busy, with a tooltip explaining how to recover.

The busy-state probe (rebase-merge/, MERGE_HEAD, etc.) was already implemented
inside `CaptureCheckpointSaga`; extracted it to `inspectGitBusyState` in
`queries.ts` so the saga and the new public `getGitBusyState(baseDir)` share
one implementation.

Generated-By: PostHog Code
Task-Id: e47ff9ba-d59b-4212-bc43-c49a5cd8db16
@adboio adboio self-assigned this May 4, 2026
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.

1 participant