11from pathlib import Path
2+ import shutil
23import subprocess
34
45
@@ -8,36 +9,39 @@ class GitManager:
89 """
910
1011 def __init__ (self , repository : Path ):
11- self .repository = Path (repository )
12+ if shutil .which ("git" ) is None :
13+ raise RuntimeError (
14+ "Git is not installed or not available in PATH."
15+ )
1216
13- def run (self , * args ):
14- """
15- Execute a git command inside the repository.
16- """
17+ self .repository = Path (repository ).resolve ()
1718
18- result = subprocess .run (
19- ["git" , * args ],
20- cwd = self .repository ,
21- capture_output = True ,
22- text = True ,
23- )
19+ def run (self , * args : str ) -> str :
20+ try :
21+ result = subprocess .run (
22+ ["git" , * args ],
23+ cwd = self .repository ,
24+ capture_output = True ,
25+ text = True ,
26+ check = True ,
27+ )
2428
25- if result .returncode != 0 :
26- raise RuntimeError (result .stderr .strip ())
29+ return result .stdout .strip ()
2730
28- return result .stdout .strip ()
31+ except subprocess .CalledProcessError as e :
32+ raise RuntimeError (e .stderr .strip ()) from e
2933
30- def status (self ):
34+ def status (self ) -> str :
3135 return self .run ("status" , "--short" )
3236
33- def add (self ):
37+ def add (self ) -> None :
3438 self .run ("add" , "." )
3539
36- def commit (self , message : str ):
40+ def commit (self , message : str ) -> None :
3741 self .run ("commit" , "-m" , message )
3842
39- def push (self ):
43+ def push (self ) -> None :
4044 self .run ("push" )
4145
42- def pull (self ):
46+ def pull (self ) -> None :
4347 self .run ("pull" )
0 commit comments