fix(git): include remote-only branches from ls-remote in branch lists (#2735)
fix(git): include remote-only branches from ls-remote in branch lists
This commit is contained in:
@@ -3747,7 +3747,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];
|
||||
@@ -3755,6 +3755,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;
|
||||
|
||||
Reference in New Issue
Block a user