Implement branching in SnapshotProvider

This commit is contained in:
Kristóf Tóth 2018-07-18 13:38:17 +02:00
parent 8e87025905
commit c279b2517f

View File

@ -17,16 +17,36 @@ class SnapshotProvider:
'GIT_COMMITTER_EMAIL': ''
}
self._head_detached = False
self._branch = 'master'
self._branches = [self._branch]
def init_repo(self):
self._run(('git', 'init'))
def take_snapshot(self):
if self._head_detached:
self._checkout_branch_from_head()
self._run(('git', 'add', '-A'))
self._run(('git', 'commit', '-m', 'Snapshot'))
def _checkout_branch_from_head(self):
head_hash = self._get_head_hash()
self._run((
'git', 'checkout',
'-b', head_hash, head_hash
))
self._branches.append(head_hash)
self._branch = head_hash
self._head_detached = False
def _get_head_hash(self):
return self._get_stdout(('git', 'rev-parse', 'HEAD'))
def restore_snapshot(self, date):
commit = self._get_commit_from_timestamp(date)
self._checkout_commit(commit)
self._head_detached = True
def _get_commit_from_timestamp(self, date):
return self._get_stdout((
@ -34,7 +54,7 @@ class SnapshotProvider:
'--date=iso',
'-n', '1',
f'--before="{date.isoformat()}"',
'master'
self._branch
))
def _checkout_commit(self, commit):