Skip to content

Commit ce72a29

Browse files
committed
chore: fix unit tests that assume initial branch is always master
1 parent dca74fe commit ce72a29

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tests/repo_finder/test_commit_finder.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023 - 2023, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2023 - 2024, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

44
"""This module tests the commit finder."""
@@ -91,7 +91,12 @@ def test_commit_finder() -> None:
9191
"""Test commit finder using mocked repository."""
9292
if os.path.exists(REPO_DIR):
9393
shutil.rmtree(REPO_DIR)
94-
git_obj = initiate_repo(REPO_DIR)
94+
git_obj = initiate_repo(
95+
REPO_DIR,
96+
git_init_options={
97+
"initial_branch": "master",
98+
},
99+
)
95100

96101
# Create a commit from a newly created file.
97102
with open(os.path.join(REPO_DIR, "file_1"), "w", encoding="utf-8") as file:

tests/slsa_analyzer/mock_git_utils.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022 - 2023, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2022 - 2024, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

44
"""
@@ -15,7 +15,7 @@
1515
from macaron.slsa_analyzer.analyze_context import AnalyzeContext
1616

1717

18-
def initiate_repo(repo_path: str | os.PathLike) -> Git:
18+
def initiate_repo(repo_path: str | os.PathLike, git_init_options: dict | None = None) -> Git:
1919
"""Init the repo at `repo_path` and return a Git wrapper of that repository.
2020
2121
This function will create the directory `repo_path` if it does not exist.
@@ -30,6 +30,8 @@ def initiate_repo(repo_path: str | os.PathLike) -> Git:
3030
Git
3131
The wrapper of the Git repository.
3232
"""
33+
git_init_options = git_init_options or {}
34+
3335
if not os.path.isdir(repo_path):
3436
os.makedirs(repo_path)
3537

@@ -38,7 +40,7 @@ def initiate_repo(repo_path: str | os.PathLike) -> Git:
3840
return git_wrapper
3941
except GitError:
4042
# No git repo at repo_path
41-
git.Repo.init(repo_path)
43+
git.Repo.init(repo_path, **git_init_options)
4244
return Git(repo_path)
4345

4446

0 commit comments

Comments
 (0)