From 5bff08b1f805393c0360aa2e6fa8b0555141bb44 Mon Sep 17 00:00:00 2001 From: yogeshwaran-c Date: Thu, 26 Mar 2026 06:30:24 +0530 Subject: [PATCH] fix: resolve branch upstream in shallow clones via git config fallback When a repository is cloned with --depth 1, git for-each-ref returns empty upstream fields because the tracking info is not fully available locally. This causes the branch upstream to be undefined, breaking features like sync, status bar upstream info, and PR creation. Add a fallback that reads branch..remote and branch..merge from git config when for-each-ref returns no upstream information. Closes #248328 --- extensions/git/src/git.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 14e61bc3f8b70..f4bc21cd2b337 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -3211,6 +3211,25 @@ export class Repository { } catch { } } + // Fallback for shallow clones: for-each-ref returns empty upstream + // fields, so we read the branch tracking config directly + if (!branch.upstream && branch.type === RefType.Head && branch.name) { + try { + const remoteResult = await this.exec(['config', '--get', `branch.${branch.name}.remote`]); + const mergeResult = await this.exec(['config', '--get', `branch.${branch.name}.merge`]); + + const remote = remoteResult.stdout.trim(); + const merge = mergeResult.stdout.trim(); + + if (remote && merge) { + const upstreamName = merge.startsWith('refs/heads/') ? merge.substring(11) : merge; + (branch as Mutable).upstream = { remote, name: upstreamName }; + } + } catch { + // No tracking config found, upstream remains undefined + } + } + return branch; }