File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 55 "io"
66 "os"
77 "path/filepath"
8+ "strings"
89
910 "github.com/gildas/go-errors"
1011 "github.com/gildas/go-logger"
@@ -21,6 +22,29 @@ func OpenGitConfig(context context.Context) (io.ReadCloser, error) {
2122 last := folder + "dummy"
2223
2324 for {
25+ // If .git is a filem (e.g. worktree), read the actual git dir from there (field gitdir)
26+ gitPath := filepath .Join (folder , ".git" )
27+ info , err := os .Stat (gitPath )
28+ if err == nil && ! info .IsDir () {
29+ log .Debugf (".git is a file, reading gitdir from there" )
30+ content , err := os .ReadFile (gitPath )
31+ if err == nil {
32+ lines := string (content )
33+ const prefix = "gitdir: "
34+ for line := range strings .SplitSeq (lines , "\n " ) {
35+ if len (line ) > len (prefix ) && line [:len (prefix )] == prefix {
36+ gitDir := line [len (prefix ):]
37+ log .Debugf ("found gitdir: %s" , gitDir )
38+ if ! filepath .IsAbs (gitDir ) {
39+ folder = filepath .Join (folder , gitDir )
40+ } else {
41+ folder = gitDir
42+ }
43+ break
44+ }
45+ }
46+ }
47+ }
2448 filename := filepath .Join (folder , ".git/config" )
2549 if folder == last {
2650 return nil , errors .NotFound .With ("file" , filename )
You can’t perform that action at this time.
0 commit comments