Skip to content

fix(web): show empty repository browse state#1380

Open
DivyamTalwar wants to merge 4 commits into
sourcebot-dev:mainfrom
DivyamTalwar:divyamtalwar/fix-821-empty-repo-browse
Open

fix(web): show empty repository browse state#1380
DivyamTalwar wants to merge 4 commits into
sourcebot-dev:mainfrom
DivyamTalwar:divyamtalwar/fix-821-empty-repo-browse

Conversation

@DivyamTalwar

@DivyamTalwar DivyamTalwar commented Jun 28, 2026

Copy link
Copy Markdown

Fixes #821

Problem

Browsing a repository with no commits falls through to generic tree-loading errors. The root tree preview calls git ls-tree HEAD, but an empty repository has no resolvable commit object yet, so both the root preview and file tree panel showed misleading failures instead of an empty-repository state.

Root cause

getFolderContents and getTree treated every git ls-tree failure as an unexpected error. For an unborn repository, a failure at the default browse ref is expected because there is no commit object yet. At the same time, empty ls-tree output is not enough to prove the repository is empty, because missing pathspecs in non-empty repos can also return no rows.

Solution

  • Detect zero-commit repositories with git rev-list --count --all after an ls-tree failure.
  • Only downgrade the failure to an empty result when the requested ref is HEAD or the repo's symbolic default branch.
  • Preserve unresolved custom refs and non-empty repository failures on the existing error path.
  • Filter root-equivalent empty path entries for file-tree requests.
  • Return explicit empty-repository state to the tree preview so missing paths do not reuse repository-empty copy.
  • Render This repository is empty in both browse tree surfaces only for confirmed empty repositories.

Tests

  • Added API coverage for empty repositories, unresolved refs in empty repositories, paths: [""], and stale open paths in empty repositories.
  • Added panel coverage proving tree preview does not infer repository emptiness from an empty item array.
  • node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test src/features/git/utils.test.ts src/features/git/emptyRepositoryApi.test.ts 'src/app/(app)/browse/components/emptyRepositoryPanels.test.tsx'
  • node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint
  • git diff --check

Risk

Low. The empty behavior only activates after ls-tree fails, the repo is confirmed to have zero commits, and the requested ref is the default empty-repo browse ref. Non-empty repositories and unresolved custom refs keep returning errors.

Not tested

Manual browser reproduction against a live empty remote repository.

Summary by CodeRabbit

  • Bug Fixes
    • Browse views now consistently show a clear “This repository is empty” message when a repository has no files, instead of generic loading/tree errors.
    • Empty repository folder and tree requests now return an empty state gracefully across browsing views.
  • Tests
    • Added automated coverage for empty repository UI states (file tree and tree preview) and for the related empty-repository data responses.
  • Documentation
    • Updated the changelog to reflect the fixed empty repository empty-state behavior.

Treat zero-commit repositories as an empty root in browse tree APIs after git ls-tree fails, and render a dedicated empty-state message instead of generic tree errors.

Constraint: Empty repositories have no resolvable HEAD, so git ls-tree fails before the existing empty-list UI path can run.

Rejected: Adding a new service error code | the browse surfaces already accept empty tree/list payloads and this keeps the API change narrow.

Confidence: high

Scope-risk: narrow

Directive: Keep non-empty unresolved refs on the error path; do not hide git failures unless rev-list confirms the repository has zero commits.

Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test src/features/git/utils.test.ts src/features/git/emptyRepositoryApi.test.ts 'src/app/(app)/browse/components/emptyRepositoryPanels.test.tsx'

Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint

Not-tested: Manual browser reproduction against a live empty remote repository.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 579b04dd-07b6-473c-8e91-cc6835d77eb2

📥 Commits

Reviewing files that changed from the base of the PR and between 4f65414 and 636a938.

📒 Files selected for processing (7)
  • packages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/pureTreePreviewPanel.tsx
  • packages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/treePreviewPanel.tsx
  • packages/web/src/app/(app)/browse/components/emptyRepositoryPanels.test.tsx
  • packages/web/src/features/git/emptyRepositoryApi.test.ts
  • packages/web/src/features/git/getFolderContentsApi.ts
  • packages/web/src/features/git/getTreeApi.ts
  • packages/web/src/features/git/utils.ts

Walkthrough

Adds git helpers and API changes to detect empty repositories and return empty results instead of errors. The browse tree panels now render “This repository is empty” for empty repository states, with tests covering the API and UI behavior.

Empty Repository Detection and UI

Layer / File(s) Summary
Repository empty helpers
packages/web/src/features/git/utils.ts
Adds helpers to detect empty repositories and compare revision names against the default branch/root ref.
API responses for empty repos
packages/web/src/features/git/getFolderContentsApi.ts, packages/web/src/features/git/getTreeApi.ts
Updates folder contents and tree APIs to return empty repository results and ignore empty normalized paths.
Empty-state browse panels
packages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/*, packages/web/src/app/(app)/browse/components/pureFileTreePanel.tsx
Passes the empty-state flag into the tree preview panel and renders the empty repository message in both browse panels.
Empty repository tests
packages/web/src/features/git/emptyRepositoryApi.test.ts, packages/web/src/app/(app)/browse/components/emptyRepositoryPanels.test.tsx
Adds API and UI tests for empty-repository handling, including fallthrough error cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 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 clearly matches the main change: improving the empty repository browse state in web.
Linked Issues check ✅ Passed The PR detects empty repositories and shows "This repository is empty" in both browse tree surfaces, satisfying the issue goals.
Out of Scope Changes check ✅ Passed The changes stay focused on empty-repository handling and related tests/docs, with no obvious unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Constraint: Sourcebot requires a follow-up changelog entry for every PR under the matching Unreleased section.

Confidence: high

Scope-risk: narrow

Directive: Keep this commit scoped to the changelog entry for PR sourcebot-dev#1380.

Tested: Not run; changelog-only follow-up.

Not-tested: Runtime tests unchanged from the implementation commit.
Merge upstream main after sourcebot-dev#1376 changed the same Unreleased changelog block, keeping both release-note entries.

Constraint: GitHub reported PR sourcebot-dev#1380 as dirty against current main.\nRejected: Rewriting the open PR branch | Avoids force-pushing an existing review branch.\nConfidence: high\nScope-risk: narrow\nDirective: This merge commit should only resolve the changelog ordering conflict.\nTested: git diff --check\nNot-tested: Targeted regression test rerun follows after the merge commit.
@DivyamTalwar DivyamTalwar marked this pull request as ready for review June 28, 2026 00:42
Preserve the empty browse state while preventing missing paths or arbitrary unresolved refs from being reported as an empty repository. The API now carries explicit empty-repository state to the tree preview and the file-tree path handling treats root-equivalent path entries consistently.

Constraint: Empty repositories have no commit object, so HEAD ls-tree fails even for the legitimate default browse state.
Rejected: Inferring repository emptiness from an empty tree listing | non-empty repos can return empty ls-tree output for missing pathspecs.
Confidence: high
Scope-risk: narrow
Directive: Only downgrade ls-tree failures to empty results after confirming the repo has zero commits and the ref is HEAD or the symbolic default branch.
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test src/features/git/utils.test.ts src/features/git/emptyRepositoryApi.test.ts 'src/app/(app)/browse/components/emptyRepositoryPanels.test.tsx'; node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint; git diff --check.
Not-tested: Manual browser reproduction against a live empty remote repository.
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.

[FR] Improve UX for empty repositories

1 participant