Skip to content

Commit 9c6dbb4

Browse files
author
perrette
committed
add a --ref option to restore-backup
1 parent c9d7a43 commit 9c6dbb4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

papers/__main__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,10 @@ def restorecmd(parser, o, config):
591591
if not config.git:
592592
parser.print_help()
593593
raise PapersExit('only valid with --git enabled')
594-
_restore_from_backupdir(config, restore_files=o.restore_files)
594+
if o.ref:
595+
_git_reset_to_commit(config, o.ref, restore_files=o.restore_files)
596+
else:
597+
_restore_from_backupdir(config, restore_files=o.restore_files)
595598

596599

597600
def gitcmd(parser, o, config):
@@ -1080,6 +1083,7 @@ def get_parser(config=None):
10801083
undop = subparsers.add_parser('undo', parents=[cfg, _restorep, _stepsp], help='Undo changes on bibtex (if --git is not enabled, only back and forth with last modification). If --git-lfs is enabled, the file entry may differ if it does not exist on disk any more, unless --restore-files was passed.')
10811084
redop = subparsers.add_parser('redo', parents=[cfg, _restorep, _stepsp], help='Redo changes on bibtex (if --git is not enabled, this has the same effect as papers undo)')
10821085
restorep = subparsers.add_parser('restore-backup', parents=[cfg, _restorep], help='Restore bibtex from backup. Also restore files if --restore-files if passed (--git-lfs only).')
1086+
restorep.add_argument('--ref', help='Optional: restore specific commit (execute `papers git whatchanged` to obtain appropriate reference)')
10831087

10841088
# git
10851089
# ===

tests/test_undo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ def test_undo(self):
8888
current = self.get_commit()
8989
self.assertEqual(current, commits[-1])
9090

91+
# Now go to specific commits
92+
self.papers(f'restore-backup --ref {commits[0]}')
93+
current = self.get_commit()
94+
self.assertEqual(current, commits[0])
95+
96+
self.papers(f'restore-backup --ref {commits[-1]}')
97+
current = self.get_commit()
98+
self.assertEqual(current, commits[-1])
99+
91100

92101
class TestTimeTravelGitLocal(LocalGitInstallTest, TimeTravelBase):
93102
pass
@@ -115,6 +124,7 @@ def test_undo(self):
115124

116125
self.assertMultiLineEqual(biblio.format(), biblio2.format())
117126

127+
118128
class TestUndoGitLocal(LocalGitLFSInstallTest):
119129

120130
def test_undo(self):

0 commit comments

Comments
 (0)