Skip to content

Conversation

@brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Jan 23, 2026

This PR fixes the issue where when the default branch changes, new commits would not be re-indexed. The issue was that the HEAD symbolic ref was not getting updated to the new default branch. This PR adds that.

Additionally, this PR makes the default branch appear in most places instead of HEAD, where applicable.

Fixes #40

Summary by CodeRabbit

  • New Features

    • Added an option to show or hide branch names in file headers.
  • Bug Fixes

    • Indexing now starts from a repository's actual default branch (not always HEAD), and respects remote default-branch changes.
    • Fetch operations update local HEAD to match the remote default branch when available and avoid exposing credentials in logs.
    • Branch-filtering in search now responds to explicit revision filters in queries; branch display logic simplified.
  • Documentation

    • Changelog updated to reflect default-branch and UI display fixes.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions

This comment has been minimized.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

Detects remote default branch during fetch, optionally updates local HEAD to that branch, exposes helpers to read remote/local default branch, uses local default branch for initial revision selection during indexing, and makes branch-display visibility in the UI query-driven.

Changes

Cohort / File(s) Summary
Git helpers & fetch behavior
packages/backend/src/git.ts
Added getRemoteDefaultBranch and getLocalDefaultBranch. fetchRepository queries remote default via git ls-remote --symref, may update local HEAD to that remote branch, and always unsets http.extraHeader in a finally block. Credential-leaking errors suppressed.
Repository indexing default selection
packages/backend/src/repoIndexManager.ts
After fetch/clone and config upsert, call getLocalDefaultBranch(path) and set initial revisions to that branch when available; fallback to HEAD if undefined.
PathHeader branch visibility prop
packages/web/src/app/[domain]/components/pathHeader.tsx
Added optional isBranchDisplayNameVisible?: boolean prop; branch display rendering now gated by isBranchDisplayNameVisible && branchDisplayName.
Query-driven branch filtering flag
packages/web/src/app/[domain]/search/components/searchResultsPage.tsx
isBranchFilteringEnabled now derives from whether searchQuery contains rev: rather than inspecting file branch lists.
FileMatch branch display wiring
packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatchContainer.tsx
branchDisplayName computation simplified to depend only on branches.length; passes isBranchDisplayNameVisible (wired to isBranchFilteringEnabled) into PathHeader.
Changelog
CHANGELOG.md
Added entries describing indexing fix for changed default branch and UI change to display default branch name instead of HEAD.

Sequence Diagram(s)

mermaid
sequenceDiagram
autonumber
participant RepoIndexManager
participant GitModule
participant RemoteGit
RepoIndexManager->>GitModule: fetchRepository(path, cloneUrl, authHeader?)
GitModule->>RemoteGit: git ls-remote --symref HEAD (query default)
alt remote default branch found
RemoteGit-->>GitModule: remote default ref (refs/heads/main)
GitModule->>GitModule: symbolic-ref HEAD -> refs/heads/main
GitModule-->>RepoIndexManager: return detected default branch
else not found
RemoteGit-->>GitModule: no symref / error
GitModule-->>RepoIndexManager: undefined
end
RepoIndexManager->>GitModule: getLocalDefaultBranch(path)
GitModule-->>RepoIndexManager: local default branch (or undefined)
RepoIndexManager->>RepoIndexManager: set initial revision = localDefault ?? HEAD

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • msukkari
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective: fixing the issue where Sourcebot doesn't index the new default branch when changed, matching the PR's primary goal.
Linked Issues check ✅ Passed The PR addresses issue #40 by implementing remote default branch detection (getRemoteDefaultBranch), local default branch resolution (getLocalDefaultBranch), and updating the indexing logic to use the current default branch instead of hard-coded HEAD.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing issue #40: backend changes detect and handle default branch updates, and UI changes display the correct default branch name instead of HEAD.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/backend/src/git.ts (1)

147-150: Guard cleanup to avoid masking fetch errors.

In the finally block (line 150), git config --unset fails with exit code 5 when the key is missing or the value pattern doesn't match, which would replace the original error caught in the except block. Wrap the cleanup in its own try-catch to prevent error masking.

Suggested fix
     } finally {
         if (authHeader) {
-            await git.raw(["config", "--unset", "http.extraHeader", authHeader]);
+            try {
+                await git.raw(["config", "--unset", "http.extraHeader", authHeader]);
+            } catch (error: unknown) {
+                logger.debug(
+                    `Failed to unset http.extraHeader for ${path}: ${
+                        error instanceof Error ? error.message : error
+                    }`
+                );
+            }
         }
     }

@brendan-kellam brendan-kellam changed the title fix(web): Default branch support fix(web): Fixed issue where Sourcebot would not index the new default branch when changed Jan 23, 2026
@brendan-kellam brendan-kellam merged commit d03b6f0 into main Jan 23, 2026
8 of 9 checks passed
@brendan-kellam brendan-kellam deleted the bkellam/fix-SOU-19 branch January 23, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sourcebot doesn't index the "default" branch if it has been changed

2 participants