Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Paste a repo → GitVerse builds a visual map + AI onboarding so contributors ca

- Visualize repository structure and key paths
- Explore commits/branches and contributor activity
- Ask AI questions about files, folders, and architecture
- **Git Time Machine & Repo Evolution Player**: Sequential chronological playback of commit logs with active file-tree animations showing additions, modifications, and deletions in real-time.
- Generate analysis jobs and track progress

## Supported Node Version
Expand Down
35 changes: 30 additions & 5 deletions lib/services/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,31 @@ export class GitService {
*/
async getBranches(signal?: AbortSignal): Promise<BranchData[]> {
try {
const { stdout: defaultBranch } = await this.spawnGit(
["symbolic-ref", "refs/remotes/origin/HEAD"],
{ timeout: DEFAULT_GIT_TIMEOUT_MS, signal },
);
const defaultBranchName = defaultBranch.trim().replace(/^refs\/remotes\/origin\//, "");
// Determine the default branch, falling back deterministically when
// origin/HEAD is not set (common on shallow / bare clones).
let defaultBranchName = "";
try {
const { stdout: defaultBranchRaw } = await this.spawnGit(
["symbolic-ref", "refs/remotes/origin/HEAD"],
{ timeout: DEFAULT_GIT_TIMEOUT_MS, signal },
);
defaultBranchName = defaultBranchRaw.trim().replace(/^refs\/remotes\/origin\//, "");
} catch {
// origin/HEAD is not set - try well-known defaults
for (const candidate of ["main", "master"]) {
try {
await this.spawnGit(
["rev-parse", "--verify", `refs/remotes/origin/${candidate}`],
{ timeout: DEFAULT_GIT_TIMEOUT_MS, signal },
);
defaultBranchName = candidate;
break;
} catch {
// candidate branch doesn't exist, try next
}
}
// If still empty, will fall back to the first discovered branch below
}

// Get both local and remote branches
const { stdout } = await this.spawnGit(
Expand Down Expand Up @@ -466,6 +486,11 @@ export class GitService {
countResults.push(...batchResults);
}

// Final fallback: if no default branch was detected, use the first discovered branch
if (!defaultBranchName && refEntries.length > 0) {
defaultBranchName = refEntries[0].name;
}

const branches: BranchData[] = refEntries.map((entry, i) => {
const result = countResults[i];
const commitCount = result.status === "fulfilled" ? result.value : 0;
Expand Down
52 changes: 49 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading