sourcebot-dev / sourcebot

Blazingly fast code search 🏎️ Deployed as a single Docker image 📦 Search million+ lines of code in your GitHub, GitLab, and Gitea repositories 🪄 MIT licensed ✅
https://sourcebot.dev/
MIT License
1.16k stars 37 forks source link

Error: getCommit("refs/heads/", "HEAD"): reference not found #59

Open OpenCode opened 2 weeks ago

OpenCode commented 2 weeks ago

Sourcebot v2.3.0

Configuration:

{
    "$schema": "https://raw.githubusercontent.com/sourcebot-dev/sourcebot/main/schemas/v2/index.json",
    "repos": [
        {
            "type": "github",
            "token": {
                "env": "GITHUB_TOKEN"
            },
            "repos": [
                ...
                "xxx/xxx",
                ...
            ]
        }
    ]
}

For a repo I receive this error:

sourcebot  | [backend] | 2024-11-06T10:55:21.124Z info: [main] Fetched github.com/xxx/xxx in 0.645s
sourcebot  | [backend] | 2024-11-06T10:55:21.124Z info: [main] Indexing github.com/xxx/xxx...
sourcebot  | [backend] | 2024-11-06T10:55:21.162Z error: [main] Command failed: zoekt-git-index -index /data/.sourcebot/index /data/.sourcebot/repos/github.com/xxx/xxx.git
sourcebot  | [backend] | 2024/11/06 10:55:21 indexGitRepo(/data/.sourcebot/repos/github.com/xxx/xxx.git, delta=false): getCommit("refs/heads/", "HEAD"): reference not found
sourcebot  | [backend] |
sourcebot  | [backend] | Error: Command failed: zoekt-git-index -index /data/.sourcebot/index /data/.sourcebot/repos/github.com/xxx/xxx.git
sourcebot  | [backend] | 2024/11/06 10:55:21 indexGitRepo(/data/.sourcebot/repos/github.com/xxx/xxx.git, delta=false): getCommit("refs/heads/", "HEAD"): reference not found
sourcebot  | [backend] |
sourcebot  | [backend] |     at ChildProcess.exithandler (node:child_process:422:12)
sourcebot  | [backend] |     at ChildProcess.emit (node:events:517:28)
sourcebot  | [backend] |     at maybeClose (node:internal/child_process:1098:16)
sourcebot  | [backend] |     at ChildProcess._handle.onexit (node:internal/child_process:303:5)
sourcebot  | [backend] | 2024-11-06T10:55:22.164Z info: [main] Fetching github.com/xxx/xxx...
brendan-kellam commented 2 weeks ago

Is this repository empty by chance? I previously had observed this issue with a empty repo so curious if it's the same problem

OpenCode commented 2 weeks ago

Is this repository empty by chance? I previously had observed this issue with a empty repo so curious if it's the same problem

Nope. There are branches and code.

brendan-kellam commented 2 weeks ago

Strange - could you:

  1. navigate into the cloned repository
  2. Run cat HEAD to see which reference HEAD is referencing
  3. Run git show-ref to see what references exist

Is the reference HEAD is referencing exist in that list?

OpenCode commented 2 weeks ago

Strange - could you:

  1. navigate into the cloned repository
  2. Run cat HEAD to see which reference HEAD is referencing
  3. Run git show-ref to see what references exist

Is the reference HEAD is referencing exist in that list?

cat HEAD
ref: refs/heads/master
-----------
git show-ref
fatal: detected dubious ownership in repository at '/home/user/sourcebot/sourcebot_workspace/.sourcebot/repos/github.com/xxx/xxx.git'
To add an exception for this directory, call:

    git config --global --add safe.directory /home/user/sourcebot/sourcebot_workspace/.sourcebot/repos/github.com/xxx/xxx.git
brendan-kellam commented 2 weeks ago

I'm unsure if the "dubious ownership" thing is actually the issue or not. Are you running Sourcebot in a container? If so, could you try running git show-ref again from inside of the container? My thinking is that maybe git is fussing because the container's user owns the repository, but the command is being run as the host user.

If you still get the dubious ownership error, could you try the suggested --add safe.directory fix and see if you still hit the indexing issue?

OpenCode commented 1 week ago

By removing the repo folder and relaunching sourcebot, the problem no longer occurs. Thanks @brendan-kellam.

er0k commented 1 week ago

Sorry to piggyback off a closed issue, but I'm seeing this same error on 3 (out of 681) of our repos. git show-ref works as expected from inside the container and I do not get the same detected dubious ownership in repository as OP, but these errors are consistent in the logs:

Error: Command failed: zoekt-git-index -index /data/.sourcebot/index -branches HEAD /data/.sourcebot/repos/github.foo.com/foo/bar.git
2024/11/14 01:02:22 indexGitRepo(/data/.sourcebot/repos/github.foo.com/foo/bar.git, delta=false): getCommit("refs/heads/", "HEAD"): reference not found

the contents of HEAD look normal to me, either ref: refs/heads/master or ref: refs/heads/main.

I've tried removing the individual repos and relaunching sourcebot, but the problem persists. Any other suggestions?

I'm using latest (v2.4.1). If you'd prefer I open a new issue just let me know.

brendan-kellam commented 1 week ago

Hey @er0k thanks for raising - I will just reopen this issue.

Could you confirm that git show-ref includes refs/heads/master or /main?

er0k commented 1 week ago

For the 3 repos that were erroring (I'll call them A, B and C):

I updated my config to exclude archived repos, and to exclude repo B explicitly, and now I'm no longer getting errors on repo C :tada:

I'm not completely sure why that fixed it... I'm happy to do some more debugging if you'd like, or we can just go ahead and close this again :smile:

brendan-kellam commented 1 week ago

Hmm that's super strange - repo A & B are expected since they are empty (will fix this in #72), but not sure why repo C was failing either 🤔. But glad it's working now!

Was repo C updated between when it was failing and it started working? One theory I have is that the repo somehow gets into a bad state when it is first cloned. If HEAD is updated on the remote, then fetching will update the local reference and fix the state.. just a theory though 🤷‍♂️

er0k commented 4 days ago

no, repo C has not been updated in over a month :shrug: