From 5ba21be60e6928b23d060b1d542ede9d24968fb4 Mon Sep 17 00:00:00 2001 From: iteye Date: Wed, 31 Dec 2025 17:21:29 +0800 Subject: [PATCH] show default branch --- src/cli/repo/contract.ts | 14 ++++++++++++++ src/cli/repo/index.ts | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cli/repo/contract.ts b/src/cli/repo/contract.ts index 967e7d3..02066d9 100644 --- a/src/cli/repo/contract.ts +++ b/src/cli/repo/contract.ts @@ -185,6 +185,20 @@ export namespace Repo { } return all; } + + export async function getDefaultBranch(repoAddress: string, chainId: number) { + const repo = await getRepoContract(repoAddress, chainId); + const [refBytes,] = await repo.getDefaultBranch(); + if (refBytes.length === 0) { + return null; + } + const branch = ethers.toUtf8String(refBytes); + return branch.startsWith("refs/heads/") + ? branch.replace("refs/heads/", "") + : branch.startsWith("refs/") + ? branch.replace("refs/", "") + : branch; + } } function normalizeBranchName(branch: string): string { diff --git a/src/cli/repo/index.ts b/src/cli/repo/index.ts index 63b4135..a83589f 100644 --- a/src/cli/repo/index.ts +++ b/src/cli/repo/index.ts @@ -147,9 +147,15 @@ repoCmd return; } + let defaultBranch: string | null = null; + try { + defaultBranch = await Repo.getDefaultBranch(repo, chainId); + } catch {} + logger.success(`Found ${list.length} branches:`); list.forEach((b, idx) => { - logger.normal(`${idx + 1}. ${b.name} (head: ${b.hash})`); + const marker = b.name === defaultBranch ? " (default)" : ""; + logger.normal(`${idx + 1}. ${b.name}${marker} (head: ${b.hash})`); }); } catch (e: any) { logger.error(`Failed to fetch branches: ${e.message}`);