aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJauhien Piatlicki <jauhien@gentoo.org>2015-08-17 00:03:21 +0200
committerJauhien Piatlicki <jauhien@gentoo.org>2015-08-17 00:29:47 +0200
commit31ae597d8dbe927729df0af181a1312fbbe84130 (patch)
tree156e0097be49058942a3e2f5115db6bf592d3704
parent[g_sorcery/package_db] new DB syncing (diff)
downloadg-sorcery-31ae597d8dbe927729df0af181a1312fbbe84130.tar.gz
g-sorcery-31ae597d8dbe927729df0af181a1312fbbe84130.tar.bz2
g-sorcery-31ae597d8dbe927729df0af181a1312fbbe84130.zip
[g_sorcery/git_syncer] detect changes of branch and remote URL
-rw-r--r--g_sorcery/git_syncer/git_syncer.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/g_sorcery/git_syncer/git_syncer.py b/g_sorcery/git_syncer/git_syncer.py
index 0f6c58e..abde034 100644
--- a/g_sorcery/git_syncer/git_syncer.py
+++ b/g_sorcery/git_syncer/git_syncer.py
@@ -12,6 +12,8 @@
"""
import os
+import shutil
+import subprocess
from g_sorcery.compatibility import TemporaryDirectory
@@ -46,8 +48,11 @@ class GITSyncer(Syncer):
branch = "master"
if os.path.exists(path):
- #TODO: allow changing of remotes/branches
- self.pull(path)
+ if self.branch_not_changed(path, branch) and self.remote_url_not_changed(path, db_uri):
+ self.pull(path)
+ else:
+ shutil.rmtree(path)
+ self.clone(db_uri, branch, path)
else:
self.clone(db_uri, branch, path)
@@ -65,3 +70,19 @@ class GITSyncer(Syncer):
def pull(self, path):
if os.system("cd " + path + " && git pull"):
raise SyncError("sync failed (pulling): " + path)
+
+
+ def branch_not_changed(self, path, branch):
+ try:
+ result = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=path).rstrip().decode("utf-8")
+ except Exception:
+ return False
+ return result == branch
+
+
+ def remote_url_not_changed(self, path, url):
+ try:
+ result = subprocess.check_output(["git", "config", "--get", "remote.origin.url"], cwd=path).rstrip().decode("utf-8")
+ except Exception:
+ return False
+ return result == url