Skip to content

Commit 4177974

Browse files
committed
add git module
1 parent aec78fb commit 4177974

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .git import Git
2+
3+
__all__ = ['Git']
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .git import Git
2+
3+
__all__ = ["Git"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import subprocess
2+
from pathlib import Path
3+
import sys
4+
5+
from ..logger import LoggerSetup
6+
7+
8+
class Git:
9+
"""Git operations handler."""
10+
11+
def __init__(self, logger=None):
12+
"""Initialize Git handler.
13+
14+
Args:
15+
logger: Optional logger instance
16+
"""
17+
self.log = logger or LoggerSetup.get_logger("gardenlinux.git")
18+
19+
def get_root(self):
20+
"""Get the root directory of the current Git repository."""
21+
try:
22+
root_dir = subprocess.check_output(
23+
["git", "rev-parse", "--show-toplevel"], text=True
24+
).strip()
25+
self.log.debug(f"Git root directory: {root_dir}")
26+
return Path(root_dir)
27+
except subprocess.CalledProcessError as e:
28+
self.log.error(
29+
"Not a git repository or unable to determine root directory."
30+
)
31+
self.log.debug(f"Git command failed with: {e}")
32+
sys.exit(1)

0 commit comments

Comments
 (0)