mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 23:41:33 +00:00
Implement branching in SnapshotProvider
This commit is contained in:
parent
8e87025905
commit
c279b2517f
@ -17,16 +17,36 @@ class SnapshotProvider:
|
|||||||
'GIT_COMMITTER_EMAIL': ''
|
'GIT_COMMITTER_EMAIL': ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self._head_detached = False
|
||||||
|
self._branch = 'master'
|
||||||
|
self._branches = [self._branch]
|
||||||
|
|
||||||
def init_repo(self):
|
def init_repo(self):
|
||||||
self._run(('git', 'init'))
|
self._run(('git', 'init'))
|
||||||
|
|
||||||
def take_snapshot(self):
|
def take_snapshot(self):
|
||||||
|
if self._head_detached:
|
||||||
|
self._checkout_branch_from_head()
|
||||||
self._run(('git', 'add', '-A'))
|
self._run(('git', 'add', '-A'))
|
||||||
self._run(('git', 'commit', '-m', 'Snapshot'))
|
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):
|
def restore_snapshot(self, date):
|
||||||
commit = self._get_commit_from_timestamp(date)
|
commit = self._get_commit_from_timestamp(date)
|
||||||
self._checkout_commit(commit)
|
self._checkout_commit(commit)
|
||||||
|
self._head_detached = True
|
||||||
|
|
||||||
def _get_commit_from_timestamp(self, date):
|
def _get_commit_from_timestamp(self, date):
|
||||||
return self._get_stdout((
|
return self._get_stdout((
|
||||||
@ -34,7 +54,7 @@ class SnapshotProvider:
|
|||||||
'--date=iso',
|
'--date=iso',
|
||||||
'-n', '1',
|
'-n', '1',
|
||||||
f'--before="{date.isoformat()}"',
|
f'--before="{date.isoformat()}"',
|
||||||
'master'
|
self._branch
|
||||||
))
|
))
|
||||||
|
|
||||||
def _checkout_commit(self, commit):
|
def _checkout_commit(self, commit):
|
||||||
|
Loading…
Reference in New Issue
Block a user