From c9ed154719282e96526a869db40c6958703094fd Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 13 Oct 2021 18:54:24 +0100 Subject: Fetch without the need to touch remotes --- lorrycontroller/readconf.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index 38b9a7f..18dda41 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -103,31 +103,26 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): def fetch_confgit(self, confdir): url = self.app_settings['confgit-url'] - origin_branch = 'origin/' + self.app_settings['confgit-branch'] + branch = self.app_settings['confgit-branch'] logging.info('Fetching 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. - 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. + # 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. - 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): -- cgit v1.2.1