Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that cluster catalog is initialized with branch master #915

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading