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

Try Git Safe Directory to Resolve fatal: not in a git directory #50

Merged
merged 1 commit into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ class ActionEnvironment(NamedTuple):
repository: str
base_branch: str
event_name: str
github_workspace: str

@classmethod
def from_env(cls, env: Mapping[str, str]) -> "ActionEnvironment":
return cls(
repository=env["GITHUB_REPOSITORY"],
base_branch=env["GITHUB_REF"],
event_name=env["GITHUB_EVENT_NAME"],
github_workspace=env["GITHUB_WORKSPACE"],
)


Expand Down
4 changes: 4 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from .run_git import (
configure_git_author,
configure_safe_directory,
create_new_git_branch,
git_commit_changes,
git_has_changes,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/run_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down