Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "hatchling.build"

[project]
name = "socketsecurity"
version = "2.1.33"
version = "2.1.34"
requires-python = ">= 3.10"
license = {"file" = "LICENSE"}
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion socketsecurity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__author__ = 'socket.dev'
__version__ = '2.1.33'
__version__ = '2.1.34'
22 changes: 22 additions & 0 deletions socketsecurity/core/git_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(self, 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}")
Loading