mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:51:31 +00:00
Implement branching in SnapshotProvider
This commit is contained in:
parent
8e87025905
commit
c279b2517f
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user