Skip to content

Commit

Permalink
traverse: fix git
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 3, 2023
1 parent c6b8ff3 commit 526c707
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions pkg/traverse/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ func GitDir(tc Context) (string, error) {
if dir, ok := tc.LookupEnv("GIT_DIR"); ok {
return filepath.ToSlash(dir), nil
}
return Parent(".git")(tc)
dir, err := GitWorkTree(tc)
if err == nil {
dir += "/.git"
}
return dir, err
}

// GitWorkTree returns the location of the root of the working directory for a non-bare repository.
func GitWorkTree(tc Context) (string, error) {
if dir, ok := tc.LookupEnv("GIT_WORK_TREE"); ok {
return filepath.ToSlash(dir), nil
}

return GitDir(tc)
return Parent(".git")(tc)
}
2 changes: 1 addition & 1 deletion pkg/traverse/traverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Parent(names ...string) func(tc Context) (string, error) {
func traverse(path string, name string) (target string, err error) {
var absPath string
if absPath, err = filepath.Abs(path); err == nil {
target = filepath.ToSlash(absPath + "/" + name)
target = filepath.ToSlash(absPath + "/" + strings.TrimSuffix(name, "/"))
if _, err = os.Stat(target); err != nil {
parent := filepath.Dir(absPath)
if parent != path {
Expand Down

0 comments on commit 526c707

Please sign in to comment.