Improve `QA::Git::Repository` so repositories and credentials persist for a whole test, but only one test
Problem
QA::Git::Repository
is the class that encapsulates use of the Git CLI. There are two problems with its current design that could have a common solution:
- Credentials are stored in
.netrc
in a temp directory named after the process id, which means every test that runs in that process uses the same.netrc
file. This lead to the problem described in gitlab-org/gitlab!43233 (merged) - Each use of
QA::Git::Repository
is expected to be isolated, but it's only partially so because of the shared credentials. This creates problems like(1)
, but it's also inefficient when we want to perform more than one action in the same repository. For example, in the following code the two blocks each clone the repository in a new temp directory instead of cloning once and then re-using the same directory:
Resource::MergeRequest.fabricate! do |merge_request|
merge_request.project = project
end
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = project
end
Proposal
Allow QA::Git::Repository
to persist a repository across all uses in a test, and then delete the repository and credentials.
We might be able to use .git/config
to store credentials instead of .netrc
.
I'm not sure of the best way to persist a repository, but one option is to make QA::Git::Repository
an attribute of the Resources that use it, and change QA::Git::Repository.perform
from:
def self.perform(*args)
Dir.mktmpdir do |dir|
Dir.chdir(dir) { super }
end
end
To something that retains the temp dir until it's no longer needed. One challenge will be to ensure that the temp dir is deleted after each test, even if it fails. One option might be to make the tmp dir a class variable and delete it in a config.after
block.