From cbb807dfb46241fc2095b9a927a056667946e064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 6 Aug 2018 14:19:18 +0200 Subject: [PATCH] Implement restore_snapshot latest commit on branch detection --- lib/tfw/components/snapshot_provider.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/tfw/components/snapshot_provider.py b/lib/tfw/components/snapshot_provider.py index 11c39c6..8fbf624 100644 --- a/lib/tfw/components/snapshot_provider.py +++ b/lib/tfw/components/snapshot_provider.py @@ -10,6 +10,7 @@ from uuid import uuid4 from dateutil import parser as dateparser +# TODO: gitignore class SnapshotProvider: def __init__(self, directory, git_dir): self._classname = self.__class__.__name__ @@ -125,6 +126,9 @@ class SnapshotProvider: def restore_snapshot(self, date): commit = self._get_commit_from_timestamp(date) + branch = self._last_valid_branch + if commit == self._latest_commit_on_branch(branch): + commit = branch self._checkout(commit) def _get_commit_from_timestamp(self, date): @@ -153,6 +157,14 @@ class SnapshotProvider: self.__last_valid_branch = self._branch return self.__last_valid_branch + def _latest_commit_on_branch(self, branch): + return self._get_stdout(( + 'git', 'log', + '-n', '1', + '--pretty=format:%H', + branch + )) + @property def all_timelines(self): return self._branches