summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-05-06 16:55:47 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-05-06 16:55:47 +0000
commit444f6f4bcbcc779df70e2edafb1fb1966f5dfab6 (patch)
tree98b74847fface8b5a38f9d644478e1b535bcf12e
parent5b5f0131f93ce5f174c57bde24f3453f2fc3cfb6 (diff)
parent3918b0904103397c7cb86819b291df680a046982 (diff)
downloadlorry-controller-444f6f4bcbcc779df70e2edafb1fb1966f5dfab6.tar.gz
Make CONFGIT mirroring more robust
Reviewed-by: Daniel Silverstone Reviewed-by: Richard Maw Reviewed-by: Paul Sherwood Richard raised the point that it'd be nice to be able to use a non-master branch, but I didn't want to tackle that in this patch.
-rw-r--r--lorrycontroller/readconf.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py
index d060067..4aa3161 100644
--- a/lorrycontroller/readconf.py
+++ b/lorrycontroller/readconf.py
@@ -101,7 +101,7 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
if not os.path.exists(confdir):
self.git_clone_confgit(confdir)
else:
- self.git_pull_confgit(confdir)
+ self.update_confgit(confdir)
def git_clone_confgit(self, confdir):
url = self.app_settings['confgit-url']
@@ -109,9 +109,29 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
logging.info('Cloning %s to %s', url, confdir)
cliapp.runcmd(['git', 'clone', '-b', branch, url, confdir])
- def git_pull_confgit(self, confdir):
+ def update_confgit(self, confdir):
logging.info('Updating CONFGIT in %s', confdir)
- cliapp.runcmd(['git', 'pull'], cwd=confdir)
+
+ # The following sequence makes the working tree mirror
+ # current upstream git repository as closely as possible.
+
+ # Get rid of any local changes. No human is meant to edit
+ # anything locally, but there may be remnants of failed
+ # runs.
+ cliapp.runcmd(['git', 'reset', '--hard'], cwd=confdir)
+
+ # Get rid of any files not known by git. This might be,
+ # say, core dumps.
+ cliapp.runcmd(['git', 'clean', '-fdx'], cwd=confdir)
+
+ # Fetch updates to remote branches.
+ cliapp.runcmd(['git', 'remote', 'update', 'origin'], cwd=confdir)
+
+ # Now move the current HEAD to wherever the remote master
+ # branch is, no questions asked. This doesn't do merging
+ # or any of the other things we don't want in this situation.
+ cliapp.runcmd(
+ ['git', 'reset', '--hard', 'origin/master'], cwd=confdir)
@property
def config_file_name(self):