Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cli/repo/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion src/cli/repo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down