2015-06-05 05:09:46 +08:00
|
|
|
# git diff --quiet e5f841bc84d31fee339191a59b8746cb4eb8074c -- ./Aircraft/
|
2015-07-29 04:26:00 +08:00
|
|
|
|
2015-06-05 05:09:46 +08:00
|
|
|
import subprocess
|
2015-07-29 04:26:00 +08:00
|
|
|
import os, sgprops
|
2015-06-05 05:09:46 +08:00
|
|
|
|
|
|
|
class GITCatalogRepository:
|
2015-07-29 04:26:00 +08:00
|
|
|
def __init__(self, node, singleAircraft = False):
|
|
|
|
self._path = node.getValue("path")
|
|
|
|
|
|
|
|
if not os.path.exists(os.path.join(self._path , ".git")):
|
|
|
|
raise RuntimeError("not a Git directory:" + self._path )
|
|
|
|
|
|
|
|
self._usesSubmodules = node.getValue("uses-submodules", False)
|
2015-06-05 05:09:46 +08:00
|
|
|
self._singleAircraft = singleAircraft
|
2015-07-29 04:26:00 +08:00
|
|
|
|
|
|
|
self._currentRevision = subprocess.check_output(["git", "rev-parse", "HEAD"],
|
2015-06-05 05:09:46 +08:00
|
|
|
cwd = self._path)
|
|
|
|
|
2015-07-29 04:26:00 +08:00
|
|
|
self._aircraftPath = None
|
|
|
|
if node.hasChild("scan-suffix"):
|
|
|
|
self._aircraftPath = os.path.join(path, node.getValue("scan-suffix"))
|
|
|
|
|
|
|
|
@property
|
|
|
|
def path(self):
|
|
|
|
return self._path
|
|
|
|
|
|
|
|
@property
|
|
|
|
def aircraftPath(self):
|
|
|
|
return self._aircraftPath
|
|
|
|
|
2015-06-05 05:09:46 +08:00
|
|
|
def hasPathChanged(self, path, oldRev):
|
|
|
|
diffArgs = ["git", "diff", "--quiet", oldRev, "--"]
|
|
|
|
if not (self._usesSubmodules and self._singleAircraft):
|
|
|
|
diffArgs.append(path)
|
2015-07-29 04:26:00 +08:00
|
|
|
|
2015-06-05 05:09:46 +08:00
|
|
|
return subprocess.call(diffArgs, cwd = self._path)
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
subprocess.call(["git", "pull"])
|
2015-07-29 04:26:00 +08:00
|
|
|
self._currentRevision = subprocess.check_output(["git", "rev-parse", "HEAD"],
|
2015-06-05 05:09:46 +08:00
|
|
|
cwd = self._path)
|
2015-07-29 04:26:00 +08:00
|
|
|
|
2015-06-05 05:09:46 +08:00
|
|
|
if self._usesSubmodules:
|
2015-07-29 04:26:00 +08:00
|
|
|
subprocess.call(["git", "submodule", "update"], cwd = self._path)
|
2015-06-05 05:09:46 +08:00
|
|
|
|
|
|
|
def scmRevisionForPath(self, path):
|
|
|
|
if self._usesSubmodules:
|
2015-07-29 04:26:00 +08:00
|
|
|
return subprocess.check_output(["git", "rev-parse", "HEAD"], cwd = self._path)
|
2015-06-05 05:09:46 +08:00
|
|
|
|
2015-07-29 04:26:00 +08:00
|
|
|
return self._currentRevision
|