From c6d3b8ad214db83868e55f8847d009f278bc7248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 19 Jul 2018 11:31:31 +0200 Subject: [PATCH] Ensure _last_valid_branch consistency --- lib/tfw/components/snapshot_provider.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/tfw/components/snapshot_provider.py b/lib/tfw/components/snapshot_provider.py index e051238..e0a90ad 100644 --- a/lib/tfw/components/snapshot_provider.py +++ b/lib/tfw/components/snapshot_provider.py @@ -53,10 +53,10 @@ class SnapshotProvider: def _checkout_new_branch_from_head(self): head_hash = self._get_head_hash() self._run(( - 'git', 'checkout', - '-b', head_hash, + 'git', 'branch', head_hash )) + self._checkout(head_hash) def _get_head_hash(self): return self._get_stdout(( @@ -68,6 +68,13 @@ class SnapshotProvider: commit = self._get_commit_from_timestamp(date) self._checkout(commit) + def _checkout(self, what): + self._run(( + 'git', 'checkout', + what + )) + self._update_last_valid_branch() + def _get_commit_from_timestamp(self, date): return self._get_stdout(( 'git', 'rev-list', @@ -77,12 +84,6 @@ class SnapshotProvider: self._last_valid_branch )) - def _checkout(self, what): - self._run(( - 'git', 'checkout', - what - )) - def _get_stdout(self, *args, **kwargs): kwargs['capture_output'] = True stdout_bytes = self._run(*args, **kwargs).stdout @@ -117,11 +118,13 @@ class SnapshotProvider: @property def _last_valid_branch(self): - current_branch = self._branch - if current_branch != 'HEAD': - self.__last_valid_branch = current_branch + self._update_last_valid_branch() return self.__last_valid_branch + def _update_last_valid_branch(self): + if not self._head_detached: + self.__last_valid_branch = self._branch + @property def _head_detached(self): return self._branch == 'HEAD'