Skip to content
Snippets Groups Projects
Commit ea6e25fe authored by Patrick Steinhardt's avatar Patrick Steinhardt
Browse files

Makefile: fix default ref format propagating into build prereqs

The `test-with-reftable` CI job executes the "test-go" target, where the
only difference to our normal test target is that it also exports the
"GIT_DEFAULT_REF_FORMAT" environment variable. This environment variable
gets exported into all dependencies, which causes us to initialize repos
other than the test repositories created by our actual unit tests with
the "reftable" format. This includes for example the bundled Git repos.

This causes an issue with CI caches: it can happen that a job gets a CI
cache that uses the "files" format for the bundled Git repos, but the
default ref format is "reftable". This causes the following error when
reinitializing the directoy:

    fatal: could not open '/builds/gitlab-org/gitaly/_build/deps/git-v2.48/.git/refs/heads' for writing: Is a directory

The issue here is that git-init(1) tries to reinitialize the repository
with the wrong ref format. When doing so it wants to write "refs/heads"
as a file containing garbage to keep other Git clients which aren't yet
aware of the "reftable" format from reading the repository. But because
the repo uses the "files" format the path is a directory, and thus
writing the file fails.

The issue can be trivially reproduced with an up-to-date Git version:

    $ git init --ref-format=files repo
    Initialized empty Git repository in /tmp/repo/.git/
    $ GIT_DEFAULT_REF_FORMAT=reftable git init repo
    fatal: could not open '/tmp/repo/.git/refs/heads' for writing: Is a directory

Even though this is an upstream bug, it still doesn't make sense for us
to propagate the `GIT_DEFAULT_REF_FORMAT` environment variable into all
build prerequisites. Fix this by using a Gitaly-specific environment
variable instead and setting it up when configuring our tests.
parent 18529fc1
No related branches found
No related tags found
Loading
......@@ -406,7 +406,7 @@ bench: ${BENCHMARK_REPO} prepare-tests
## Since the reftable code isn't tagged in Git yet, to run it locally
## we have to specify the git version too:
## 'GIT_DEFAULT_REF_FORMAT=reftable OVERRIDE_GIT_VERSION="v99.99.99" GIT_VERSION="master" make test-go'
test-with-reftable: export GIT_DEFAULT_REF_FORMAT = reftable
test-with-reftable: export GITALY_TEST_REF_FORMAT = reftable
test-with-reftable: test-go
.PHONY: test-with-sha256
......
......@@ -16,7 +16,7 @@ import (
// DefaultReferenceBackend is the default reftable backend used for running tests.
var DefaultReferenceBackend = func() git.ReferenceBackend {
if val, enabled := os.LookupEnv("GIT_DEFAULT_REF_FORMAT"); enabled && val == "reftable" {
if val, enabled := os.LookupEnv("GITALY_TEST_REF_FORMAT"); enabled && val == "reftable" {
return git.ReferenceBackendReftables
}
......
......@@ -123,6 +123,12 @@ func configure() (_ func(), returnedErr error) {
}
}
if refFormat := os.Getenv("GITALY_TEST_REF_FORMAT"); len(refFormat) > 0 {
if err := os.Setenv("GIT_DEFAULT_REF_FORMAT", refFormat); err != nil {
return nil, fmt.Errorf("setting default ref format: %w", err)
}
}
// We need to make sure that we're gitconfig-clean: Git should not pick up
// gitconfig files from anywhere but the repository itself in case they're configured to
// ignore them. We set that configuration by default in our tests to have a known-good
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment