5.0 KiB
APP-4218: Git operations dialogs compare against the branch's actual parent
Summary
The Push and Create PR dialogs must scope their "Included commits" / "Changes" previews to the commits and changes on top of the current branch's actual parent branch — the branch it was created off of. Today the dialogs fall back to comparing against the repo's main branch when there's no upstream, so a branch-off-a-branch surfaces every inherited commit as if it were new work.
Problem
When a user creates feature-b off feature-a (no upstream yet) and opens the Push / Publish dialog, the "Included commits" list shows every commit between main and HEAD — including all commits inherited from feature-a. The same thing happens in the Create PR dialog's "Changes" list, its AI-generated title/description input, and the resulting gh pr create command (which targets the repo default branch). The user only wants to publish / open a PR for the work they actually did on feature-b.
The correct base is a property of the branch itself (what it was branched from), not a user choice. The dialogs should detect that base from the repo and use it directly.
Goals
- The Push / Publish and Create PR dialogs compare against the current branch's actual parent branch, not unconditionally against main.
- Parent-branch detection is automatic, simple, and independent of the code review pane's diff-mode selector.
- The Create PR dialog targets the detected parent via
gh pr create --base <parent>. - Fall back to the repo's main branch when detection can't produce a parent, preserving today's common-path behavior.
Non-goals
- Letting the user override the detected parent (follow-up if needed).
- Reflecting the detected parent anywhere outside the Push and Create PR dialogs.
- Changing the Commit dialog's behavior beyond its
Commit and create PRchain.
Figma
Figma: none provided (text/list-only change inside existing dialog chrome).
Behavior
- Parent branch. The current branch's parent is the local or remote-tracking branch whose tip is an ancestor of
HEADand is closest toHEAD— i.e.git merge-base --is-ancestor <candidate> HEADsucceeds andgit rev-list --count <candidate>..HEADis smallest among the candidates. The current branch is excluded from the candidate pool. If no candidate qualifies, the parent is the repo's detected main branch. - Push / Publish dialog — included commits. The "Included commits" list shows the commits in
<parent>..HEAD. When there are no commits ahead of the parent, the list is empty and the primary Publish button is disabled. - Create PR dialog — changes list. The "Changes" list shows the files and per-file stats from
<parent>..<end_ref>, where<end_ref>isorigin/<current_branch>if that remote ref exists, otherwiseHEAD— same end-ref pattern as today. - Create PR dialog — AI inputs. The diff fed into AI title / description generation and the branch commit-message list also use
<parent>..<end_ref>. - Create PR dialog — PR target.
gh pr createis invoked with--base <parent>so the PR targets the parent branch. If the parent ref is a remote-tracking ref (e.g.origin/feature-a), theorigin/prefix is stripped before passing togh. Applies to both the AI-generated-content path and the--fillfallback. - Detection timing. Parent detection runs whenever the dialog's helpers need it; results are not cached long-term. Rebases and new branches are picked up on the next open.
- Fallback errors. If detection fails outright (not a git repo, git call errors) the dialogs use the main branch. If
gh pr create --base <parent>is rejected by GitHub (e.g. the parent isn't pushed to origin), the user sees the existing generic "Git operation failed." toast; the dialog does not silently retry without--base. - Commit dialog. The Commit dialog itself is unchanged. Its
Commit and create PRchain uses the detected parent for the final PR step (same rule as §5). - Independence from the diff-mode dropdown. The pane's diff-mode dropdown is unrelated to detection. Changing it doesn't change the dialogs' previews, and detection doesn't change the dropdown.
Success criteria
- On
feature-bbranched fromfeature-a(no upstream on either), the Publish dialog shows only the commits added onfeature-b, and the Create PR dialog's Changes list shows only files changed onfeature-b. - Confirming Create PR in that setup runs
gh pr create --base feature-a …and the resulting PR targetsfeature-a. - On a fresh branch off
main(no upstream), the Publish dialog showsmain..HEAD— same commits as today. - After rebasing
feature-bontomain, the next dialog open detectsmainas the parent and shows the rebased range. - If no branch is an ancestor of
HEAD, detection falls back tomain— no error. - The Commit dialog's
Commit and create PRchain targets the detected parent. - The pane's diff-mode dropdown and the dialogs' previews are independent: changing one does not change the other.