Skip to content

Commit

Permalink
Be mindful of safe.bareRepository in the tests
Browse files Browse the repository at this point in the history
As of Git v2.38.0, there is an option to prevent Git from accessing bare
repositories unless asked for explicitly (via `--git-dir` or `GIT_DIR`):
`safe.bareRepository`.

The tests of `git sizer`, however, assume that Git will access a bare
repository when the current directory points inside that repository.
This only works if `safe.bareRepository` indicates that this is safe.

If that is not the case, i.e. if `safe.bareRepository` is set to
`explicit`, Git demands that the environment variable `GIT_DIR` is set
(either explicitly, or via `--git-dir`) when accessing bare
repositories.

So let's set `GIT_DIR` for the test cases that work on bare
repositories.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Dec 14, 2023
1 parent d605cdb commit fb78b41
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions git_sizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ func TestRefSelections(t *testing.T) {
args := []string{"--show-refs", "--no-progress", "--json", "--json-version=2"}
args = append(args, p.args...)
cmd := exec.Command(executable, args...)
cmd.Dir = repo.Path
cmd.Env = append(
os.Environ(),
"GIT_DIR="+repo.Path,
)
var stdout bytes.Buffer
cmd.Stdout = &stdout
var stderr bytes.Buffer
Expand Down Expand Up @@ -519,7 +522,10 @@ References (included references marked with '+'):

args := append([]string{"--show-refs", "-v", "--no-progress"}, p.args...)
cmd := exec.Command(executable, args...)
cmd.Dir = repo.Path
cmd.Env = append(
os.Environ(),
"GIT_DIR="+repo.Path,
)
var stdout bytes.Buffer
cmd.Stdout = &stdout
var stderr bytes.Buffer
Expand Down

0 comments on commit fb78b41

Please sign in to comment.