Skip to content

Commit 3c0a944

Browse files
committed
NewRepository: don't join paths if gitDir is already absolute
If the output of `git -C path rev-parse --git-dir` is already an absolute path (e.g., if `git-sizer` is run from within a subdirectory of a working copy), then it is incorrect to call `filepath.Join()` because that function doesn't treat absolute paths specially. So check `filepath.IsAbs()` first, and only call `filepath.Join()` if the path is not already absolute. Fixes #10.
1 parent ecfdc3d commit 3c0a944

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

git/git.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ func NewRepository(path string) (*Repository, error) {
9090
return nil, err
9191
}
9292
}
93-
gitDir := filepath.Join(path, string(bytes.TrimSpace(out)))
93+
gitDir := string(bytes.TrimSpace(out))
94+
if !filepath.IsAbs(gitDir) {
95+
gitDir = filepath.Join(path, gitDir)
96+
}
9497
repo := &Repository{
9598
path: gitDir,
9699
}

0 commit comments

Comments
 (0)