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 From 5475de95a694a007a1b7bfb23074401ebcb9cacd Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 13 Oct 2021 18:51:11 +0100 Subject: Drop duplicate hard reset --- lorrycontroller/readconf.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index 02f11a2..38b9a7f 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -116,11 +116,6 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): # 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) -- cgit v1.2.1 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 From 490ee6706ef8d4fd884696b4947871b76bc3c437 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 13 Oct 2021 18:55:15 +0100 Subject: Remove unclear comment --- lorrycontroller/readconf.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index 18dda41..f677bd1 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -109,9 +109,6 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): if not os.path.exists(confdir): cliapp.runcmd(['git', 'init', 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) -- cgit v1.2.1 From c6b1f7f3ad0c5bcc5492d7a1ac0c00be824feb00 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 13 Oct 2021 19:03:30 +0100 Subject: Bump copyright year --- lorrycontroller/readconf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index f677bd1..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 -- cgit v1.2.1