diff --git a/src/main/git/repo.test.ts b/src/main/git/repo.test.ts index 7cecf3df7..f89140c53 100644 --- a/src/main/git/repo.test.ts +++ b/src/main/git/repo.test.ts @@ -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', diff --git a/src/main/git/repo.ts b/src/main/git/repo.ts index fff8ad5a5..ddf56073e 100644 --- a/src/main/git/repo.ts +++ b/src/main/git/repo.ts @@ -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//. 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