Skip to content

Support bare repos in Git.init #5

Description

@cjw296

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions