Skip to content

Commit

Permalink
add a --ref option to restore-backup
Browse files Browse the repository at this point in the history
  • Loading branch information
perrette committed May 10, 2023
1 parent c9d7a43 commit 9c6dbb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion papers/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,10 @@ def restorecmd(parser, o, config):
if not config.git:
parser.print_help()
raise PapersExit('only valid with --git enabled')
_restore_from_backupdir(config, restore_files=o.restore_files)
if o.ref:
_git_reset_to_commit(config, o.ref, restore_files=o.restore_files)
else:
_restore_from_backupdir(config, restore_files=o.restore_files)


def gitcmd(parser, o, config):
Expand Down Expand Up @@ -1080,6 +1083,7 @@ def get_parser(config=None):
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.')
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)')
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).')
restorep.add_argument('--ref', help='Optional: restore specific commit (execute `papers git whatchanged` to obtain appropriate reference)')

# git
# ===
Expand Down
10 changes: 10 additions & 0 deletions tests/test_undo.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ def test_undo(self):
current = self.get_commit()
self.assertEqual(current, commits[-1])

# Now go to specific commits
self.papers(f'restore-backup --ref {commits[0]}')
current = self.get_commit()
self.assertEqual(current, commits[0])

self.papers(f'restore-backup --ref {commits[-1]}')
current = self.get_commit()
self.assertEqual(current, commits[-1])


class TestTimeTravelGitLocal(LocalGitInstallTest, TimeTravelBase):
pass
Expand Down Expand Up @@ -115,6 +124,7 @@ def test_undo(self):

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


class TestUndoGitLocal(LocalGitLFSInstallTest):

def test_undo(self):
Expand Down

0 comments on commit 9c6dbb4

Please sign in to comment.