diff --git a/pyproject.toml b/pyproject.toml index d2f79a4..7f81e51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.1.33" +version = "2.1.35" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index c03b717..c0d1c92 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.1.33' +__version__ = '2.1.35' diff --git a/socketsecurity/core/git_interface.py b/socketsecurity/core/git_interface.py index 93fefb5..a10efc5 100644 --- a/socketsecurity/core/git_interface.py +++ b/socketsecurity/core/git_interface.py @@ -12,6 +12,7 @@ class Git: def __init__(self, path: str): self.path = path + self.ensure_safe_directory(path) self.repo = Repo(path) assert self.repo self.head = self.repo.head @@ -409,3 +410,24 @@ def is_on_default_branch(self) -> bool: except Exception as error: log.debug(f"Error checking if on default branch: {error}") return False + + @staticmethod + def ensure_safe_directory(path: str) -> None: + # Ensure the repo is marked as safe for git (prevents SHA empty/dubious ownership errors) + try : + import subprocess + abs_path = os.path.abspath(path) + # Get all safe directories + result = subprocess.run([ + "git", "config", "--global", "--get-all", "safe.directory" + ], capture_output=True, text=True) + safe_dirs = result.stdout.splitlines() if result.returncode == 0 else [] + if abs_path not in safe_dirs: + subprocess.run([ + "git", "config", "--global", "--add", "safe.directory", abs_path + ], check=True) + log.debug(f"Added {abs_path} to git safe.directory config.") + else: + log.debug(f"{abs_path} already present in git safe.directory config.") + except Exception as safe_error: + log.debug(f"Failed to set safe.directory for git: {safe_error}") \ No newline at end of file