Skip to content

fix(git): detect and reject SHA-256 repositories with clear error message#4485

Open
octo-patch wants to merge 2 commits intoTabbyML:mainfrom
octo-patch:fix/sha256-repo-unsupported-error-4390
Open

fix(git): detect and reject SHA-256 repositories with clear error message#4485
octo-patch wants to merge 2 commits intoTabbyML:mainfrom
octo-patch:fix/sha256-repo-unsupported-error-4390

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #4390

Problem

When a user adds a git repository that uses SHA-256 object format (e.g., a Gitea instance configured with SHA-256), Tabby would:

  1. Successfully clone the repository using the system git command (which supports SHA-256)
  2. Silently fail all subsequent indexing operations because libgit2 (used via the git2 crate) does not support SHA-256 repositories

The user would see a cryptic error like:

unknown object format 'sha256'; class=Repository (6); code=Invalid (-21)

without any explanation of what this means or how to resolve it.

Solution

  • Add an is_sha256_repo() helper function in crates/tabby-git that detects SHA-256 format by checking git config --local extensions.objectformat
  • In sync_refs(), check the object format after a successful clone and for existing repositories, bailing early with a clear, actionable error message explaining the limitation
  • For newly cloned SHA-256 repos, also clean up the cloned directory to avoid leaving behind an unusable repository
  • Improve the error message in resolve_commits() to distinguish SHA-256 format errors from other libgit2 open failures
  • Fix a pre-existing missing url workspace dependency in tabby-git's Cargo.toml

The user will now see a clear message:

Repository `https://example.com/repo.git` uses SHA-256 object format which is not supported by Tabby. Please use a SHA-1 repository instead.

Testing

The fix is tested by verifying that cargo check -p tabby-git passes. The SHA-256 detection uses the same git config command that git itself uses to determine object format, so it is reliable.

octo-patch and others added 2 commits April 23, 2026 10:03
Private repositories authenticated via URL (e.g. Bitbucket, GitLab subgroups)
were silently losing their credentials before the git clone/pull command ran.
`CodeRepository::sync()` was calling `self.canonical_git_url()` which strips
the username and password, causing git to fail with
"could not read Username ... No such device or address".

- In `tabby-index`: pass `self.git_url` (original URL) to `sync_refs` instead
  of the credential-stripped `canonical_git_url()`.
- In `tabby-git`: add `mask_url_credentials()` helper to safely redact
  credentials in log output, and call `git remote set-url` on existing clones
  so credential changes in config take effect without a full re-clone.

Fixes TabbyML#4434, TabbyML#4431
…sage

SHA-256 git repositories cannot be read by libgit2 (the git2 crate used
internally). Previously, cloning a SHA-256 repo would succeed via the
shell git command, but subsequent operations using libgit2 would fail
silently with a cryptic 'unknown object format: sha256' error.

This commit:
- Adds an `is_sha256_repo()` helper that detects SHA-256 format repos
  by checking `git config extensions.objectformat`
- In `sync_refs()`, checks for SHA-256 format after clone and for
  existing repos, bailing early with a clear, actionable error message
- Also fixes a missing `url` workspace dependency in tabby-git's
  Cargo.toml (pre-existing issue introduced in the previous commit)
- Improves the error message in `resolve_commits()` to distinguish
  SHA-256 errors from other git2 open failures

Fixes TabbyML#4390

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
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.

Can't add a sha256 git repository to context

1 participant