Ensure _last_valid_branch consistency

This commit is contained in:
Kristóf Tóth 2018-07-19 11:31:31 +02:00
parent dd056a37bb
commit c6d3b8ad21

View File

@ -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'