From 4f04d3134af3d3dfeb3bab7f5a4745a9c2160064 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 13 Oct 2021 18:50:09 +0100 Subject: readconf: unify clone and update into single fetch method --- lorrycontroller/readconf.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index 8f95035..02f11a2 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -99,23 +99,18 @@ 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]) + origin_branch = 'origin/' + self.app_settings['confgit-branch'] + 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 @@ -136,7 +131,6 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): # 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) -- cgit v1.2.1