Skip to content

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

Closed

Description

@OpenCode

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...

Activity

  1. brendan-kellam commented on Nov 6, 2024

    @brendan-kellam
    Contributor

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

  2. OpenCode commented on Nov 6, 2024

    @OpenCode
    Author

    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.

  3. brendan-kellam commented on Nov 7, 2024

    @brendan-kellam
    Contributor

    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?

  4. OpenCode commented on Nov 7, 2024

    @OpenCode
    Author

    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
    
  5. brendan-kellam commented on Nov 7, 2024

    @brendan-kellam
    Contributor

    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?

  6. OpenCode commented on Nov 12, 2024

    @OpenCode
    Author

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

  7. er0k commented on Nov 14, 2024

    @er0k
    Contributor

    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.

  8. brendan-kellam commented on Nov 14, 2024

    @brendan-kellam
    Contributor

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

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

  9. er0k commented on Nov 14, 2024

    @er0k
    Contributor

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

    • repo A is an empty repo
    • repo B is an archived, empty repo
    • repo C is neither archived, nor empty, and refs/heads/master is included in git show-ref

    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 🎉

    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 😄

  10. brendan-kellam commented on Nov 15, 2024

    @brendan-kellam
    Contributor

    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 🤷‍♂️

  11. er0k commented on Nov 18, 2024

    @er0k
    Contributor

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

  12. brendan-kellam commented on Nov 27, 2024

    @brendan-kellam
    Contributor

    Hmm ok not sure then.. will close this issue for now and we can re-open if it comes back up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions