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): def _checkout_new_branch_from_head(self):
head_hash = self._get_head_hash() head_hash = self._get_head_hash()
self._run(( self._run((
'git', 'checkout', 'git', 'branch',
'-b', head_hash,
head_hash head_hash
)) ))
self._checkout(head_hash)
def _get_head_hash(self): def _get_head_hash(self):
return self._get_stdout(( return self._get_stdout((
@ -68,6 +68,13 @@ class SnapshotProvider:
commit = self._get_commit_from_timestamp(date) commit = self._get_commit_from_timestamp(date)
self._checkout(commit) self._checkout(commit)
def _checkout(self, what):
self._run((
'git', 'checkout',
what
))
self._update_last_valid_branch()
def _get_commit_from_timestamp(self, date): def _get_commit_from_timestamp(self, date):
return self._get_stdout(( return self._get_stdout((
'git', 'rev-list', 'git', 'rev-list',
@ -77,12 +84,6 @@ class SnapshotProvider:
self._last_valid_branch self._last_valid_branch
)) ))
def _checkout(self, what):
self._run((
'git', 'checkout',
what
))
def _get_stdout(self, *args, **kwargs): def _get_stdout(self, *args, **kwargs):
kwargs['capture_output'] = True kwargs['capture_output'] = True
stdout_bytes = self._run(*args, **kwargs).stdout stdout_bytes = self._run(*args, **kwargs).stdout
@ -117,11 +118,13 @@ class SnapshotProvider:
@property @property
def _last_valid_branch(self): def _last_valid_branch(self):
current_branch = self._branch self._update_last_valid_branch()
if current_branch != 'HEAD':
self.__last_valid_branch = current_branch
return self.__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 @property
def _head_detached(self): def _head_detached(self):
return self._branch == 'HEAD' return self._branch == 'HEAD'