aboutsummaryrefslogtreecommitdiffstats
path: root/repository/gogit.go
diff options
context:
space:
mode:
authorAlec Lanter <kintar1900@gmail.com>2023-01-23 10:10:11 -0600
committerAlec Lanter <kintar1900@gmail.com>2023-01-23 10:10:11 -0600
commit70f405e7b15148ba0c3de89355b7dd5cb3befa60 (patch)
tree150592e9dff33f44bc3e0f15ceca0b85cd1a9e26 /repository/gogit.go
parente97df9c8102c92701489cb2693294064f1488b4b (diff)
downloadgit-bug-70f405e7b15148ba0c3de89355b7dd5cb3befa60.tar.gz
test: resolve changes for PR #1004, add unit test, fix issue uncovered by unit test
Diffstat (limited to 'repository/gogit.go')
-rw-r--r--repository/gogit.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/repository/gogit.go b/repository/gogit.go
index 18f7fb59..649614fb 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -172,25 +172,24 @@ func detectGitPath(path string) (string, error) {
if err == nil {
if !fi.IsDir() {
// See if our .git item is a dotfile that holds a submodule reference
- dotfile, err := os.Open(fi.Name())
+ dotfile, err := os.Open(filepath.Join(path, fi.Name()))
if err != nil {
- // Can't open" error
+ // Can't open error
return "", fmt.Errorf(".git exists but is not a directory or a readable file: %w", err)
}
// We aren't going to defer the dotfile.Close, because we might keep looping, so we have to be sure to
// clean up before returning an error
reader := bufio.NewReader(dotfile)
line, _, err := reader.ReadLine()
+ _ = dotfile.Close()
if err != nil {
- _ = dotfile.Close()
return "", fmt.Errorf(".git exists but is not a direcctory and cannot be read: %w", err)
}
dotContent := string(line)
if strings.HasPrefix(dotContent, "gitdir:") {
- _ = dotfile.Close()
// This is a submodule parent path link. Strip the prefix, clean the string of whitespace just to
// be safe, and return
- dotContent = strings.TrimSpace(dotContent[7:])
+ dotContent = strings.TrimSpace(strings.TrimPrefix(dotContent, "gitdir: "))
return dotContent, nil
}
return "", fmt.Errorf(".git exist but is not a directory")