summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-05-06 16:49:49 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-05-06 16:49:49 +0000
commit3918b0904103397c7cb86819b291df680a046982 (patch)
tree6050cb9cd2aa35d8576d2c00f712e33d7a9adf00
parent5e2584a7936af5413588232be1f0df7b4cef18c1 (diff)
downloadlorry-controller-3918b0904103397c7cb86819b291df680a046982.tar.gz
Update CONFGIT mirror more robustly
The sequence of git operations suggested by Daniel Silverstone.
-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):