Skip to content

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

Open
DivyamTalwar wants to merge 5 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 5 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 show a centered “This repository is empty” empty state for empty repositories, avoiding generic loading/tree errors across the file tree and tree preview panels.
    • Empty repository folder/tree requests now resolve as successful empty results instead of error responses.
  • Tests
    • Added coverage for empty repository UI states and for empty-repository git folder/tree API behavior.
  • Documentation
    • Updated the changelog under Unreleased to reflect the improved 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: 3d8167d3-1893-4e02-9936-b50cf7e85d1f

📥 Commits

Reviewing files that changed from the base of the PR and between 636a938 and 93fdd51.

📒 Files selected for processing (1)
  • CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

Walkthrough

Adds empty-repository detection in git utilities and APIs, returns empty repository responses instead of errors, and renders “This repository is empty” in the browse tree panels. Tests and changelog text were updated to match the new behavior.

Changes

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, CHANGELOG.md
Adds API and UI tests for empty-repository handling, and records the browse-tree empty-state fix in the changelog.

Sequence Diagram(s)

sequenceDiagram
  participant TreePreviewPanel
  participant getFolderContentsApi
  participant getTreeApi
  participant git
  participant isEmptyRepositoryRootRef
  TreePreviewPanel->>getFolderContentsApi: request folder contents
  getFolderContentsApi->>git: ls-tree
  git-->>getFolderContentsApi: error for empty repo
  getFolderContentsApi->>isEmptyRepositoryRootRef: detect empty root ref
  isEmptyRepositoryRootRef-->>getFolderContentsApi: true
  getFolderContentsApi-->>TreePreviewPanel: { items, isRepositoryEmpty }
  TreePreviewPanel->>getTreeApi: request tree
  getTreeApi->>git: ls-tree
  git-->>getTreeApi: error for empty repo
  getTreeApi->>isEmptyRepositoryRootRef: detect empty root ref
  isEmptyRepositoryRootRef-->>getTreeApi: true
  getTreeApi-->>TreePreviewPanel: empty root tree
Loading

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: showing an empty repository state in the web browse UI.
Linked Issues check ✅ Passed The changes satisfy #821 by detecting empty repos and rendering a clear empty-state message instead of generic loading errors.
Out of Scope Changes check ✅ Passed The PR stays focused on empty-repository browse UX plus tests and changelog updates, with no unrelated functional changes.
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.
…empty-repo-browse

# Conflicts:
#	CHANGELOG.md
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