-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit.py
More file actions
executable file
·32 lines (26 loc) · 945 Bytes
/
git.py
File metadata and controls
executable file
·32 lines (26 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import subprocess
from pathlib import Path
import sys
from ..logger import LoggerSetup
class Git:
"""Git operations handler."""
def __init__(self, logger=None):
"""Initialize Git handler.
Args:
logger: Optional logger instance
"""
self.log = logger or LoggerSetup.get_logger("gardenlinux.git")
def get_root(self):
"""Get the root directory of the current Git repository."""
try:
root_dir = subprocess.check_output(
["git", "rev-parse", "--show-toplevel"], text=True
).strip()
self.log.debug(f"Git root directory: {root_dir}")
return Path(root_dir)
except subprocess.CalledProcessError as e:
self.log.error(
"Not a git repository or unable to determine root directory."
)
self.log.debug(f"Git command failed with: {e}")
sys.exit(1)