From 2b4de249872c976a27ca8b7bfadbcbd2d7112321 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:50:36 -0800 Subject: [PATCH] fix(git): keep explicit refspec precedence in push destination proof --- .../branch-review-heads-real-git.test.ts | 47 +++++++++++++++---- .../git/remotes/git-review-branch-source.ts | 3 +- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/main/github/client/lookup/branch-review-heads-real-git.test.ts b/src/main/github/client/lookup/branch-review-heads-real-git.test.ts index 056a78e9779..a18a6133649 100644 --- a/src/main/github/client/lookup/branch-review-heads-real-git.test.ts +++ b/src/main/github/client/lookup/branch-review-heads-real-git.test.ts @@ -44,29 +44,51 @@ vi.mock('../../repositories/github-api-repository-remote-probe', () => ({ import { getConfiguredPushHead } from './branch-review-heads' it.each([ - { name: 'nothing', config: [['push.default', 'nothing']], destination: null }, + { + name: 'nothing', + config: [['push.default', 'nothing']], + destination: null, + pushSucceeds: false + }, { name: 'unmapped refspec', config: [['remote.fork.push', 'refs/heads/other:refs/heads/other']], - destination: null + destination: null, + pushSucceeds: true + }, + { + name: 'unmapped refspec overrides upstream mode', + config: [ + ['push.default', 'upstream'], + ['remote.fork.push', 'refs/heads/other:refs/heads/other'] + ], + destination: null, + pushSucceeds: true }, { name: 'simple with another upstream branch', config: [['push.default', 'simple']], - destination: null + destination: null, + pushSucceeds: false + }, + { + name: 'current', + config: [['push.default', 'current']], + destination: 'feature', + pushSucceeds: true }, - { name: 'current', config: [['push.default', 'current']], destination: 'feature' }, { name: 'explicit mapping overrides nothing', config: [ ['push.default', 'nothing'], ['remote.fork.push', 'refs/heads/feature:refs/heads/published'] ], - destination: 'published' + destination: 'published', + pushSucceeds: true } ])( 'matches real Git publication while keeping discovery usable: $name', - async ({ config, destination }) => { + async ({ config, destination, pushSucceeds }) => { const directory = await mkdtemp(path.join(tmpdir(), 'push-head-')) const repo = path.join(directory, 'checkout') const fork = path.join(directory, 'fork.git') @@ -98,16 +120,25 @@ it.each([ '-m', 'initial' ]) + await git(['branch', 'other']) await git(['remote', 'add', 'fork', fork]) await git(['config', 'branch.feature.remote', 'fork']) await git(['config', 'branch.feature.merge', 'refs/heads/other']) for (const [key, value] of config) { await git(['config', key, value]) } - const push = await run(repo, ['push', '--dry-run']) + const push = await run(repo, ['push']) + expect(push.code === 0, push.stderr).toBe(pushSucceeds) const source = (await readGitReviewBranchSources(git, ['feature'])).get('feature') if (destination === null) { - expect(push.code).not.toBe(0) + const feature = await run(directory, [ + '--git-dir', + fork, + 'rev-parse', + '--verify', + 'refs/heads/feature' + ]) + expect(feature.code).not.toBe(0) // GitLab can still discover a manually published branch despite a disabled plain push. expect(source).toMatchObject({ branchName: 'feature', diff --git a/src/shared/git/remotes/git-review-branch-source.ts b/src/shared/git/remotes/git-review-branch-source.ts index fe7b1451d84..a4badedf591 100644 --- a/src/shared/git/remotes/git-review-branch-source.ts +++ b/src/shared/git/remotes/git-review-branch-source.ts @@ -148,13 +148,14 @@ export async function readGitReviewBranchSources( if ((get('push.default') ?? 'simple') === 'simple' && tracked && tracked !== branch) { pushBranchName = null } - if (get('push.default') === 'upstream') { + if (specs.length === 0 && get('push.default') === 'upstream') { if (!merge) { throw new Error('Review upstream is unavailable') } pushBranchName = tracked ?? null } } else if ( + specs.length === 0 && get('push.default') === 'upstream' && explicitRemote && remote !== trackedRemote