Git.init currently covers only non-bare repos:
def init(self, user: User | None = None, branch: str | None = None) -> None:
makedirs(self.path, exist_ok=True)
command = ['init']
if branch:
command.extend(['-b', branch])
self(*command)
self._set_user(user)
It would be useful for it to grow a bare: bool = False parameter that adds --bare to the init, while keeping the user and branch handling.
The user part is the real value: worktrees of a bare repo share its config, so a test that commits in such a worktree needs an identity configured in the bare repo — exactly what init/Repo.make already guarantee for normal repos ("so neither depends on the git config of the machine the tests are running on"). Without it, git falls back to guessing an identity from the OS, which works on a developer Mac (gecos is populated) but dies on CI runners with fatal: empty ident name not allowed.
Today that means hand-rolling in test fixtures, reaching around the public API:
Git(tmpdir.path)('init', '--bare', '-b', 'main', str(repo))
bare = Git(repo)
bare('config', 'user.name', DEFAULT_USER.name)
bare('config', 'user.email', DEFAULT_USER.email)
where Git.init(user=DEFAULT_USER, branch='main', bare=True) would say the same thing in one call and keep the machine-independence guarantee.
Git.initcurrently covers only non-bare repos:It would be useful for it to grow a
bare: bool = Falseparameter that adds--bareto theinit, while keeping theuserandbranchhandling.The
userpart is the real value: worktrees of a bare repo share its config, so a test that commits in such a worktree needs an identity configured in the bare repo — exactly whatinit/Repo.makealready guarantee for normal repos ("so neither depends on the git config of the machine the tests are running on"). Without it, git falls back to guessing an identity from the OS, which works on a developer Mac (gecos is populated) but dies on CI runners withfatal: empty ident name not allowed.Today that means hand-rolling in test fixtures, reaching around the public API:
where
Git.init(user=DEFAULT_USER, branch='main', bare=True)would say the same thing in one call and keep the machine-independence guarantee.