aboutsummaryrefslogtreecommitdiffstats
path: root/repository/gogit_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2023-03-04 13:10:38 +0100
committerMichael Muré <batolettre@gmail.com>2023-03-04 13:20:09 +0100
commit27c96a4044f05a338d6ac6187135e6b9ac487e9f (patch)
treef50c44dde7e68722ec8001e9a974d3901e78fda7 /repository/gogit_test.go
parentd9ac658392cc09d42928f68a60b0e337f7dc7d04 (diff)
downloadgit-bug-27c96a4044f05a338d6ac6187135e6b9ac487e9f.tar.gz
repo: improve support for gitdir indirection
- add a limited reader to avoid abuse - support recusive indirection (up to depth 10) - check that the pointed to repo does exist
Diffstat (limited to 'repository/gogit_test.go')
-rw-r--r--repository/gogit_test.go22
1 files changed, 9 insertions, 13 deletions
diff --git a/repository/gogit_test.go b/repository/gogit_test.go
index 2bec97a5..21acd5df 100644
--- a/repository/gogit_test.go
+++ b/repository/gogit_test.go
@@ -1,6 +1,7 @@
package repository
import (
+ "fmt"
"os"
"path"
"path/filepath"
@@ -84,19 +85,14 @@ func TestGoGitRepo_Indexes(t *testing.T) {
}
func TestGoGit_DetectsSubmodules(t *testing.T) {
- expectedPath := "../foo/bar"
- submoduleData := "gitdir: " + expectedPath
+ repo := CreateGoGitTestRepo(t, false)
+ expected := filepath.Join(goGitRepoDir(t, repo), "/.git")
+
d := t.TempDir()
- if f, err := os.Create(filepath.Join(d, ".git")); err != nil {
- t.Fatal("could not create necessary temp file:", err)
- } else {
- t.Log(f.Name())
- if _, err := f.Write([]byte(submoduleData)); err != nil {
- t.Fatal("could not write necessary data to temp file:", err)
- }
- _ = f.Close()
- }
- result, err := detectGitPath(d)
+ err := os.WriteFile(filepath.Join(d, ".git"), []byte(fmt.Sprintf("gitdir: %s", expected)), 0600)
+ require.NoError(t, err)
+
+ result, err := detectGitPath(d, 0)
assert.Empty(t, err)
- assert.Equal(t, expectedPath, result)
+ assert.Equal(t, expected, result)
}