fix: detect branch conflicts for slashed remotes (#4080)

This commit is contained in:
Neil
2026-05-31 04:00:09 -07:00
committed by GitHub
parent 90eb25566d
commit b0ad5cb103
2 changed files with 16 additions and 5 deletions
+10
View File
@@ -216,6 +216,16 @@ describe('searchBaseRefs (widened glob)', () => {
createRemoteRef(tmpDir, 'origin/feature/something', sha)
createRemoteRef(tmpDir, 'upstream/feature/something', sha)
expect(
await getBranchConflictKind(tmpDir, 'feature/something', 'origin/feature/something')
).toBe('remote')
})
it('reports remote conflicts when the remote name contains a slash', async () => {
const sha = getHeadSha(tmpDir)
git(tmpDir, ['remote', 'add', 'foo/bar', 'https://example.invalid/repo.git'])
createRemoteRef(tmpDir, 'foo/bar/feature/something', sha)
const result = await getBranchConflictKind(
tmpDir,
'feature/something',
+6 -5
View File
@@ -772,20 +772,21 @@ export async function getBranchConflictKind(
}
try {
const remoteNames = (await listRemoteNames(path)).sort((a, b) => b.length - a.length)
const { stdout } = await gitExecFileAsync(
['for-each-ref', '--format=%(refname)', 'refs/remotes'],
{ cwd: path }
)
// Why: refs have the form refs/remotes/<remote>/<branch>. We strip the
// first three segments so that e.g. "feature/dashboard" only matches
// "refs/remotes/origin/feature/dashboard", not "refs/remotes/origin/other/feature/dashboard".
const hasRemoteConflict = stdout.split('\n').some((ref) => {
const trimmed = ref.trim()
if (isAllowedRemoteBaseRef(trimmed, allowedBaseRef)) {
return false
}
const parts = trimmed.split('/')
return parts.slice(3).join('/') === branchName
const shortRef = trimmed.replace(/^refs\/remotes\//, '')
// Why: git allows slashes in remote names. Use the configured remote
// list so foo/bar/feature resolves as branch "feature" for remote
// "foo/bar", matching searchBaseRefDetails.
return resolveLocalBranchName(trimmed, shortRef, remoteNames) === branchName
})
return hasRemoteConflict ? 'remote' : null