Skip to content

Commit

Permalink
Merge pull request #915 from projectsyn/fix/catalog-init
Browse files Browse the repository at this point in the history
Ensure that cluster catalog is initialized with branch `master`
  • Loading branch information
simu authored Feb 9, 2024
2 parents dc19c5c + 26c9023 commit 9c743fb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commodore/gitrepo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(
if not force_init and targetdir.exists():
self._repo = Repo(targetdir)
else:
self._repo = Repo.init(targetdir, bare=bare)
self._repo = Repo.init(targetdir, bare=bare, initial_branch="master")

if remote:
self.remote = remote
Expand Down
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""
from __future__ import annotations

import os

from pathlib import Path
from typing import Protocol

Expand All @@ -23,6 +25,23 @@ def __call__(self, args: list[str]) -> Result:
...


@pytest.fixture(autouse=True)
def gitconfig(tmp_path: Path) -> Path:
"""Ensure that tests have a predictable empty gitconfig.
We set autouse=True, so that the fixture is automatically used for all
tests. Tests that want to access the mock gitconfig can explicitly specify
the fixutre, so they get the path to the mock gitconfig.
"""
os.environ["GIT_CONFIG_NOSYSTEM"] = "true"
os.environ["HOME"] = str(tmp_path)
os.environ["XDG_CONFIG_HOME"] = str(tmp_path / ".config")
gitconfig = tmp_path / ".config" / "git" / "config"
os.makedirs(gitconfig.parent, exist_ok=True)

return gitconfig


@pytest.fixture
def cli_runner() -> RunnerFunc:
r = CliRunner()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_gitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,14 @@ def test_gitrepo_is_ahead_of_remote_local_branch(tmp_path: Path):
# verify that our local branch is ahead of both local and remote tracking master
assert len(list(r.repo.iter_commits("master..local"))) == 1
assert len(list(r.repo.iter_commits("origin/master..local"))) == 1


def test_gitrepo_init_always_master(gitconfig: Path, tmp_path: Path):
cfg = git.config.GitConfigParser(file_or_files=gitconfig, read_only=False)
cfg.add_value("init", "defaultBranch", "main").write()

r = gitrepo.GitRepo(None, tmp_path / "repo.git")
r.commit("Initial commit")

assert len(r._repo.heads) == 1
assert r._repo.heads[0].name == "master"

0 comments on commit 9c743fb

Please sign in to comment.