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

chore: explicitly git init with the master branch in tests requiring it #589

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions tests/repo_finder/test_commit_finder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 - 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2023 - 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

"""This module tests the commit finder."""
Expand Down Expand Up @@ -91,7 +91,12 @@ def test_commit_finder() -> None:
"""Test commit finder using mocked repository."""
if os.path.exists(REPO_DIR):
shutil.rmtree(REPO_DIR)
git_obj = initiate_repo(REPO_DIR)
git_obj = initiate_repo(
REPO_DIR,
git_init_options={
"initial_branch": "master",
},
)

# Create a commit from a newly created file.
with open(os.path.join(REPO_DIR, "file_1"), "w", encoding="utf-8") as file:
Expand Down
8 changes: 5 additions & 3 deletions tests/slsa_analyzer/mock_git_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022 - 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2022 - 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

"""
Expand All @@ -15,7 +15,7 @@
from macaron.slsa_analyzer.analyze_context import AnalyzeContext


def initiate_repo(repo_path: str | os.PathLike) -> Git:
def initiate_repo(repo_path: str | os.PathLike, git_init_options: dict | None = None) -> Git:
"""Init the repo at `repo_path` and return a Git wrapper of that repository.

This function will create the directory `repo_path` if it does not exist.
Expand All @@ -30,6 +30,8 @@ def initiate_repo(repo_path: str | os.PathLike) -> Git:
Git
The wrapper of the Git repository.
"""
git_init_options = git_init_options or {}

if not os.path.isdir(repo_path):
os.makedirs(repo_path)

Expand All @@ -38,7 +40,7 @@ def initiate_repo(repo_path: str | os.PathLike) -> Git:
return git_wrapper
except GitError:
# No git repo at repo_path
git.Repo.init(repo_path)
git.Repo.init(repo_path, **git_init_options)
return Git(repo_path)


Expand Down
Loading