Skip to content

Commit d605cdb

Browse files
committed
TestRepo: for bare repositories, use NewRepositoryFromGitDir()
There's no need to deduce the `GIT_DIR` for a bare repository.
1 parent f9aec50 commit d605cdb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

internal/testutils/repoutils.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
// TestRepo represents a git repository used for tests.
2121
type TestRepo struct {
2222
Path string
23+
bare bool
2324
}
2425

2526
// NewTestRepo creates and initializes a test repository in a
@@ -37,6 +38,7 @@ func NewTestRepo(t *testing.T, bare bool, pattern string) *TestRepo {
3738

3839
return &TestRepo{
3940
Path: path,
41+
bare: bare,
4042
}
4143
}
4244

@@ -89,9 +91,15 @@ func (repo *TestRepo) Clone(t *testing.T, pattern string) *TestRepo {
8991
func (repo *TestRepo) Repository(t *testing.T) *git.Repository {
9092
t.Helper()
9193

92-
r, err := git.NewRepositoryFromPath(repo.Path)
93-
require.NoError(t, err)
94-
return r
94+
if repo.bare {
95+
r, err := git.NewRepositoryFromGitDir(repo.Path)
96+
require.NoError(t, err)
97+
return r
98+
} else {
99+
r, err := git.NewRepositoryFromPath(repo.Path)
100+
require.NoError(t, err)
101+
return r
102+
}
95103
}
96104

97105
// localEnvVars is a list of the variable names that should be cleared

0 commit comments

Comments
 (0)