Skip to content

Commit 1058567

Browse files
authored
chore: explicitly git init with the master branch in tests requiring it (#589)
Signed-off-by: Nathan Nguyen <[email protected]>
1 parent 776c0d7 commit 1058567

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

tests/repo_finder/test_commit_finder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 11 additions & 4 deletions
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,21 +15,28 @@
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.
2222
2323
Parameters
2424
----------
25-
repo_path : str or os.PathLike
25+
repo_path : str | os.PathLike
2626
The path to the target repo.
2727
28+
git_init_options : dict
29+
Additional keyword arguments passed to the `git.Repo.init` method.
30+
Each key is the name of the argument and each value is the corresponding value
31+
for the argument.
32+
2833
Returns
2934
-------
3035
Git
3136
The wrapper of the Git repository.
3237
"""
38+
git_init_options = git_init_options or {}
39+
3340
if not os.path.isdir(repo_path):
3441
os.makedirs(repo_path)
3542

@@ -38,7 +45,7 @@ def initiate_repo(repo_path: str | os.PathLike) -> Git:
3845
return git_wrapper
3946
except GitError:
4047
# No git repo at repo_path
41-
git.Repo.init(repo_path)
48+
git.Repo.init(repo_path, **git_init_options)
4249
return Git(repo_path)
4350

4451

0 commit comments

Comments
 (0)