From 3d1bcb85c64d4fc7271212c538a563b236f082a6 Mon Sep 17 00:00:00 2001 From: Maksudul Haque Date: Sat, 17 Dec 2022 10:57:52 +0000 Subject: [PATCH] Try Git Safe Directory --- src/config.py | 2 ++ src/main.py | 4 ++++ src/run_git.py | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/src/config.py b/src/config.py index bc75a83..7dd6417 100644 --- a/src/config.py +++ b/src/config.py @@ -27,6 +27,7 @@ class ActionEnvironment(NamedTuple): repository: str base_branch: str event_name: str + github_workspace: str @classmethod def from_env(cls, env: Mapping[str, str]) -> "ActionEnvironment": @@ -34,6 +35,7 @@ def from_env(cls, env: Mapping[str, str]) -> "ActionEnvironment": repository=env["GITHUB_REPOSITORY"], base_branch=env["GITHUB_REF"], event_name=env["GITHUB_EVENT_NAME"], + github_workspace=env["GITHUB_WORKSPACE"], ) diff --git a/src/main.py b/src/main.py index fb96b0e..7539c1f 100644 --- a/src/main.py +++ b/src/main.py @@ -22,6 +22,7 @@ ) from .run_git import ( configure_git_author, + configure_safe_directory, create_new_git_branch, git_commit_changes, git_has_changes, @@ -442,6 +443,9 @@ def _get_all_actions(self, data: Any) -> Generator[str, None, None]: gha_utils.echo("Using Configuration:") gha_utils.echo(pprint.pformat(user_configuration._asdict())) + # Configure Git Safe Directory + configure_safe_directory(action_environment.github_workspace) + # Configure Git Author configure_git_author( user_configuration.git_committer_username, diff --git a/src/run_git.py b/src/run_git.py index 0fb177e..9f7002c 100644 --- a/src/run_git.py +++ b/src/run_git.py @@ -15,6 +15,16 @@ def configure_git_author(username: str, email: str) -> None: run_subprocess_command(["git", "config", "user.email", email]) +def configure_safe_directory(directory: str) -> None: + """ + Configure git safe.directory. + """ + with gha_utils.group("Configure Git Safe Directory"): + run_subprocess_command( + ["git", "config", "--global", "--add", "safe.directory", directory] + ) + + def create_new_git_branch(base_branch_name: str, new_branch_name: str) -> None: """ Create a new git branch from base branch.