Hide Create PR banner for branches whose remote was deleted - #81
Merged
Conversation
The "Create Pull Request" banner treated a branch as published whenever git reported a configured upstream. But git reports the configured upstream even when the remote-tracking ref no longer exists (e.g. a stale local `master` still tracking `origin/master` after the remote renamed its default to `main`). Such a branch has nothing on the remote to open a PR from, so the banner offered a dead action. Require the upstream remote branch to actually exist among the branch's remote refs before offering the banner. The gate is extracted into a pure, unit-tested createPrBannerUrl() so every condition is covered directly rather than through the hook.
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.
Problem
The Create Pull Request banner appeared for a local branch whose configured upstream no longer exists on the remote — for example a stale local
masterthat still tracksorigin/masterafter the remote renamed its default tomain. git's porcelain keeps reporting the configured upstream (# branch.upstream origin/master) even though the remote-tracking ref is gone, so GitGrove considered the branch "published" and offered a PR that GitHub can't actually create (there is no such branch on the remote to compare from).Seen on the Avalonia repo: on
master(tracking a deletedorigin/master, remote default is nowmain), GitGrove offered "Create Pull Request" for a dead compare.Note: the existing default-branch check (
current === defaultBranch) was working correctly and is unrelated —mastergenuinely isn't Avalonia's default (mainis).Fix
Treat a branch as published only when its upstream remote branch actually exists among the branch's remote refs — not merely when one is configured. This also naturally covers any branch whose remote was deleted.
The banner gate is extracted from the
usePullRequestshook into a pure, unit-testedcreatePrBannerUrl()so every condition is covered directly.Tests
New
pr-banner.test.ts(8 tests), including the exact scenario: a stalemastertracking a deletedorigin/master→ no banner.bun test,typecheck, andlintall green.