Skip to content

repo.Head() on a git worktree fails with reference not found #1580

@staktrace

Description

@staktrace

If you do this:

git clone https://github.com/go-git/go-git
cd go-git
git worktree add ../go-git-wt

and then use go-git to open the repo at go-git-wt and call repo.Head()

	repo, err := git.PlainOpenWithOptions(dir, &git.PlainOpenOptions{DetectDotGit: true})
...
	head, err := repo.Head()

this returns a "reference not found" error. The go-git/.git/worktrees/go-git-wt/HEAD file contains a symbolic ref to something like refs/heads/go-git-wt but that ref is not found under go-git/.git/worktrees/go-git-wt. Instead it is in the primary git dir at go-git/.git/refs/heads/go-git-wt and the go-git library doesn't look in there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions