fix(walkthrough): use remote default branch
This commit is contained in:
@@ -3367,6 +3367,7 @@ export async function getBranches(directory) {
|
||||
const allBranches = result.all;
|
||||
const remoteBranches = allBranches.filter(branch => branch.startsWith('remotes/'));
|
||||
const activeRemoteBranches = await filterActiveRemoteBranches(git, remoteBranches);
|
||||
const defaultBranches = await getRemoteDefaultBranches(git);
|
||||
|
||||
const filteredAll = [
|
||||
...allBranches.filter(branch => !branch.startsWith('remotes/')),
|
||||
@@ -3376,7 +3377,8 @@ export async function getBranches(directory) {
|
||||
return {
|
||||
all: filteredAll,
|
||||
current: result.current,
|
||||
branches: result.branches
|
||||
branches: result.branches,
|
||||
defaultBranches,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Failed to get branches:', error);
|
||||
@@ -3384,6 +3386,28 @@ export async function getBranches(directory) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getRemoteDefaultBranches(git) {
|
||||
try {
|
||||
const refs = await git.raw([
|
||||
'for-each-ref',
|
||||
'--format=%(refname) %(symref)',
|
||||
'refs/remotes',
|
||||
]);
|
||||
return Object.fromEntries(
|
||||
refs.trim().split('\n').flatMap((line) => {
|
||||
const [ref, symbolicRef] = line.split(' ');
|
||||
const match = ref.match(/^refs\/remotes\/([^/]+)\/HEAD$/);
|
||||
const prefix = match ? `refs/remotes/${match[1]}/` : '';
|
||||
return match && typeof symbolicRef === 'string' && symbolicRef.startsWith(prefix)
|
||||
? [[match[1], symbolicRef.slice(prefix.length)]]
|
||||
: [];
|
||||
})
|
||||
);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function filterActiveRemoteBranches(git, remoteBranches) {
|
||||
try {
|
||||
const remotes = await git.getRemotes();
|
||||
|
||||
Reference in New Issue
Block a user