You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
When a linked worktree's HEAD ref is a tracking-branch, this code will attempt to open the ref using the path in the .git/worktree which is not where the refs are stored.
This example doesn't technically git gc the worktree but the scenario is the same.
Output
$ make
git clone [email protected]:src-d/go-git.git
Cloning into 'go-git'...
cd go-git; git fetch --all
go-git-bug/go-git
Fetching origin
cd go-git; git worktree add -b new-ref ../go-git-linked/
go-git-bug/go-git
Preparing worktree (new branch 'new-ref')
HEAD is now at 1a7db85bca70 Merge pull request #1231 from alexandear/fix-typos
go build -o bugged
---- Works as expected
go-git-bug/go-git
git rev-parse --git-dir
.git
git rev-parse HEAD
1a7db85bca7027d90afdb5ce711622aaac9feaed
2019/12/01 11:39:36 worktree: go-git-bug/go-git
2019/12/01 11:39:36 1a7db85bca7027d90afdb5ce711622aaac9feaed refs/heads/master
2019/12/01 11:39:36 1a7db85bca7027d90afdb5ce711622aaac9feaed refs/heads/new-ref
2019/12/01 11:39:36 head: 1a7db85bca7027d90afdb5ce711622aaac9feaed refs/heads/master
---- Bug this does not work as expected
go-git-bug/go-git-linked
git rev-parse --git-dir
go-git-bug/go-git/.git/worktrees/go-git-linked
git rev-parse HEAD
1a7db85bca7027d90afdb5ce711622aaac9feaed
2019/12/01 11:39:36 worktree: go-git-bug/go-git-linked
2019/12/01 11:39:36 head: reference not found
make: *** [bug] Error 1
There is also a scenario for linked worktrees when the worktree's .git/ref/heads file can be garbage collected (git gc in the worktree, because it is the same as a ref/remotes?) so the above will always fail.
The text was updated successfully, but these errors were encountered:
nicerobot
changed the title
This is wrong when referenced from a linked worktree
repo.Head() fails when referenced from a linked worktree after being garbage collected
Dec 1, 2019
In this linked worktree example, the ObjectStorage and ReferenceStorage should be based on the contents of the go-git/.git/worktrees/go-git-linked/gitdir file.
It looks like this would be solved by parsing commondir in the worktree folder (i.e. .git/worktrees/<worktree>/commondir) which points back to the main .git folder. While #1098 parses this, it hasn't been touched in almost a year.
When a linked worktree's HEAD ref is a tracking-branch, this code will attempt to open the ref using the path in the
.git/worktree
which is not where the refs are stored.go-git/storage/filesystem/dotgit/dotgit.go
Lines 927 to 931 in 0d1a009
Example
Demo
This example doesn't technically
git gc
the worktree but the scenario is the same.Output
Call-stack
Additionally
There is also a scenario for linked worktrees when the worktree's
.git/ref/heads
file can be garbage collected (git gc
in the worktree, because it is the same as aref/remotes
?) so the above will always fail.The text was updated successfully, but these errors were encountered: