Skip to content

Commit

Permalink
TestRepo: for bare repositories, use NewRepositoryFromGitDir()
Browse files Browse the repository at this point in the history
There's no need to deduce the `GIT_DIR` for a bare repository.
  • Loading branch information
mhagger committed Dec 14, 2023
1 parent f9aec50 commit d605cdb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/testutils/repoutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
// TestRepo represents a git repository used for tests.
type TestRepo struct {
Path string
bare bool
}

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

return &TestRepo{
Path: path,
bare: bare,
}
}

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

r, err := git.NewRepositoryFromPath(repo.Path)
require.NoError(t, err)
return r
if repo.bare {
r, err := git.NewRepositoryFromGitDir(repo.Path)
require.NoError(t, err)
return r
} else {
r, err := git.NewRepositoryFromPath(repo.Path)
require.NoError(t, err)
return r
}
}

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

0 comments on commit d605cdb

Please sign in to comment.