Skip to content

Commit bf88577

Browse files
authored
Merge pull request #50 from saadmk11/safe-dir
Try Git Safe Directory to Resolve `fatal: not in a git directory`
2 parents fcc8d10 + 3d1bcb8 commit bf88577

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ class ActionEnvironment(NamedTuple):
2727
repository: str
2828
base_branch: str
2929
event_name: str
30+
github_workspace: str
3031

3132
@classmethod
3233
def from_env(cls, env: Mapping[str, str]) -> "ActionEnvironment":
3334
return cls(
3435
repository=env["GITHUB_REPOSITORY"],
3536
base_branch=env["GITHUB_REF"],
3637
event_name=env["GITHUB_EVENT_NAME"],
38+
github_workspace=env["GITHUB_WORKSPACE"],
3739
)
3840

3941

src/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from .run_git import (
2424
configure_git_author,
25+
configure_safe_directory,
2526
create_new_git_branch,
2627
git_commit_changes,
2728
git_has_changes,
@@ -442,6 +443,9 @@ def _get_all_actions(self, data: Any) -> Generator[str, None, None]:
442443
gha_utils.echo("Using Configuration:")
443444
gha_utils.echo(pprint.pformat(user_configuration._asdict()))
444445

446+
# Configure Git Safe Directory
447+
configure_safe_directory(action_environment.github_workspace)
448+
445449
# Configure Git Author
446450
configure_git_author(
447451
user_configuration.git_committer_username,

src/run_git.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ def configure_git_author(username: str, email: str) -> None:
1515
run_subprocess_command(["git", "config", "user.email", email])
1616

1717

18+
def configure_safe_directory(directory: str) -> None:
19+
"""
20+
Configure git safe.directory.
21+
"""
22+
with gha_utils.group("Configure Git Safe Directory"):
23+
run_subprocess_command(
24+
["git", "config", "--global", "--add", "safe.directory", directory]
25+
)
26+
27+
1828
def create_new_git_branch(base_branch_name: str, new_branch_name: str) -> None:
1929
"""
2030
Create a new git branch from base branch.

0 commit comments

Comments
 (0)