From e383be0149d025fa9966a7d2560a2d7eea72b8b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 3 Aug 2018 11:55:51 +0200 Subject: [PATCH] Fix restore_snapshot() choking on timestamps before initial commit --- lib/tfw/components/snapshot_provider.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tfw/components/snapshot_provider.py b/lib/tfw/components/snapshot_provider.py index f0cd6ba..2c8dcee 100644 --- a/lib/tfw/components/snapshot_provider.py +++ b/lib/tfw/components/snapshot_provider.py @@ -129,13 +129,24 @@ class SnapshotProvider: self._checkout(commit) def _get_commit_from_timestamp(self, date): - return self._get_stdout(( + commit = self._get_stdout(( 'git', 'rev-list', '--date=iso', '-n', '1', f'--before="{date.isoformat()}"', self._last_valid_branch )) + if not commit: + commit = self._get_oldest_parent_of_head() + return commit + + def _get_oldest_parent_of_head(self): + return self._get_stdout(( + 'git', + 'rev-list', + '--max-parents=0', + 'HEAD' + )) @property def _last_valid_branch(self):