Skip to content

Commit 3581089

Browse files
committed
Adhere to optional git options
1 parent 4d7e54f commit 3581089

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/sasctl/pzmm/gitIntegration.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,30 @@
55
from uuid import UUID
66
from warnings import warn
77
import zipfile
8-
import git
9-
from git import Repo
108
import io
119

1210
from .._services.model_repository import ModelRepository as mr
1311
from ..core import RestObj
1412

13+
try:
14+
import git
15+
from git import Repo
16+
except ImportError:
17+
git = None
18+
19+
def checkGitStatus():
20+
'''Check to see if GitPython has been installed and if a valid git executable
21+
exists on the target system. If one of those two conditions is not met, then
22+
a RunTime error is raised.
23+
24+
Raises
25+
------
26+
RuntimeError
27+
Raised if an invalid git setup for git integration is detected.
28+
'''
29+
if git is None:
30+
raise RuntimeError("The 'GitPython' package and a valid git executable is required" +
31+
" for use of the git integration functions.")
1532

1633
def getZippedModel(model, gPath, project=None):
1734
"""Retrieve a zipped file containing all of the model contents or a specified
@@ -280,6 +297,8 @@ def gitRepoPush(cls, gPath, commitMessage, remote="origin", branch="main"):
280297
branch : string
281298
Branch name for the target pull branch from remote, by default 'main'
282299
"""
300+
checkGitStatus()
301+
283302
repo = Repo(gPath)
284303
repo.git.add(all=True)
285304
repo.index.commit(commitMessage)
@@ -299,6 +318,8 @@ def gitRepoPull(cls, gPath, remote="origin", branch="main"):
299318
branch : string
300319
Branch name for the target pull branch from remote, by default 'main'
301320
"""
321+
checkGitStatus()
322+
302323
repo = git.Git(gPath)
303324
repo.pull(remote, branch)
304325

0 commit comments

Comments
 (0)