From c0df5e6d0d56ab4261c04046f892605fbfdd4834 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Thu, 4 Jan 2024 00:12:09 +1000 Subject: [PATCH 1/2] chore: explicity git init with the `master` branch in tests requiring it Signed-off-by: Nathan Nguyen --- tests/repo_finder/test_commit_finder.py | 9 +++++++-- tests/slsa_analyzer/mock_git_utils.py | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/repo_finder/test_commit_finder.py b/tests/repo_finder/test_commit_finder.py index db151de2e..b64418553 100644 --- a/tests/repo_finder/test_commit_finder.py +++ b/tests/repo_finder/test_commit_finder.py @@ -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.""" @@ -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: diff --git a/tests/slsa_analyzer/mock_git_utils.py b/tests/slsa_analyzer/mock_git_utils.py index 2d962cd7b..e7d6400d2 100644 --- a/tests/slsa_analyzer/mock_git_utils.py +++ b/tests/slsa_analyzer/mock_git_utils.py @@ -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/. """ @@ -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. @@ -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) @@ -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) From c78edd0734249d495a67c60f9d2be7d60d53b5f3 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Fri, 23 Feb 2024 12:15:37 +1000 Subject: [PATCH 2/2] chore: add docstring for the git_init_options argument Signed-off-by: Nathan Nguyen --- tests/slsa_analyzer/mock_git_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/slsa_analyzer/mock_git_utils.py b/tests/slsa_analyzer/mock_git_utils.py index e7d6400d2..680515983 100644 --- a/tests/slsa_analyzer/mock_git_utils.py +++ b/tests/slsa_analyzer/mock_git_utils.py @@ -22,9 +22,14 @@ def initiate_repo(repo_path: str | os.PathLike, git_init_options: dict | None = Parameters ---------- - repo_path : str or os.PathLike + repo_path : str | os.PathLike The path to the target repo. + git_init_options : dict + Additional keyword arguments passed to the `git.Repo.init` method. + Each key is the name of the argument and each value is the corresponding value + for the argument. + Returns ------- Git