diff options
author | Ben Brown <ben@demerara.io> | 2021-10-15 08:35:13 +0000 |
---|---|---|
committer | Ben Brown <ben@demerara.io> | 2021-10-15 08:35:13 +0000 |
commit | b49d223bd8c2ba2bfd6ce97059fd67902e0e2a8d (patch) | |
tree | 554a78ac9dd90b8faa11355aab25c8563b4f1732 | |
parent | 6481be75c568c64c6448915b3ff1fa088a056e5a (diff) | |
parent | c6b1f7f3ad0c5bcc5492d7a1ac0c00be824feb00 (diff) | |
download | lorry-controller-b49d223bd8c2ba2bfd6ce97059fd67902e0e2a8d.tar.gz |
Merge branch 'benbrown/confgit-fetch' into 'master'
Tidy up confgit fetching
See merge request CodethinkLabs/lorry/lorry-controller!29
-rw-r--r-- | lorrycontroller/readconf.py | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index 8f95035..333c291 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2020 Codethink Limited +# Copyright (C) 2014-2021 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -99,46 +99,27 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): def get_confgit(self): if self.app_settings['debug-real-confgit']: confdir = self.app_settings['configuration-directory'] - if not os.path.exists(confdir): - self.git_clone_confgit(confdir) - else: - self.update_confgit(confdir) + self.fetch_confgit(confdir) - def git_clone_confgit(self, confdir): + def fetch_confgit(self, confdir): url = self.app_settings['confgit-url'] branch = self.app_settings['confgit-branch'] - logging.info('Cloning %s to %s', url, confdir) - cliapp.runcmd(['git', 'clone', '-b', branch, url, confdir]) + logging.info('Fetching CONFGIT in %s', confdir) - def update_confgit(self, confdir): - logging.info('Updating CONFGIT in %s', confdir) + if not os.path.exists(confdir): + cliapp.runcmd(['git', 'init', confdir]) - # First ensure that the confgit repo is using the correct - # upstream source. - url = self.app_settings['confgit-url'] - cliapp.runcmd(['git', 'remote', 'set-url', 'origin', url], 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) + # Fetch updates to remote branch. + cliapp.runcmd(['git', 'fetch', '--prune', url, branch], 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. - origin_branch = 'origin/' + self.app_settings['confgit-branch'] - cliapp.runcmd( - ['git', 'reset', '--hard', origin_branch], cwd=confdir) + # Now move the current HEAD to whatever we just fetched, 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', 'FETCH_HEAD'], cwd=confdir) @property def config_file_name(self): |