fix(git): include remote-only branches from ls-remote in branch lists (#2098)

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
This commit is contained in:
Serhii Dziupin
2026-08-06 19:49:02 +00:00
co-authored by Serhii Dziupin
parent fe331c093b
commit 510472951a
3 changed files with 62 additions and 2 deletions
+20 -1
View File
@@ -3490,7 +3490,7 @@ async function filterActiveRemoteBranches(git, remoteBranches) {
}
}));
return remoteBranches.filter(remoteBranch => {
const activeBranches = remoteBranches.filter(remoteBranch => {
const match = remoteBranch.match(/^remotes\/[^\/]+\/(.+)$/);
if (!match) return false;
const remoteName = remoteBranch.split('/')[1];
@@ -3498,6 +3498,25 @@ async function filterActiveRemoteBranches(git, remoteBranches) {
if (unreachableRemotes.has(remoteName)) return true;
return branchesByRemote.get(remoteName)?.has(branchName) ?? false;
});
// A branch pushed to the remote that was never fetched locally has no
// remote-tracking ref, so `git branch` never reports it — but ls-remote
// just told us it exists. Add those so a freshly pushed branch shows up
// without requiring a fetch first (#2098). Unreachable remotes have no
// ls-remote data and therefore add nothing here; their local view above
// is preserved unchanged.
const seenBranches = new Set(activeBranches);
for (const [remoteName, actualRemoteBranches] of branchesByRemote) {
for (const branchName of actualRemoteBranches) {
const qualifiedBranch = `remotes/${remoteName}/${branchName}`;
if (!seenBranches.has(qualifiedBranch)) {
seenBranches.add(qualifiedBranch);
activeBranches.push(qualifiedBranch);
}
}
}
return activeBranches;
} catch (error) {
console.warn('Failed to filter active remote branches, returning all:', error.message);
return remoteBranches;