From 1a9ca888a8b1a709c95f9a3082fc4028b90cc616 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Fri, 20 Apr 2018 10:01:50 -0700 Subject: [PATCH] infinitepush: don't push empty backups in new clones Summary: If the infinitepush backup state is empty (indicating this is probably a new clone of a repository), and there are no commits or bookmarks to be backed up, don't push a backupbundle that clears all the heads and bookmarks of any backups that have the same servername and path. This might be a reclone of the repository, and the user might want to restore the backup. When the first commit or bookmark is made in the new repository, the old backup will be cleared at that point. Differential Revision: D7669728 fbshipit-source-id: bec859bbbbee6b631efb4483a8fedbad8f3bcbac --- hgext/infinitepush/backupcommands.py | 9 +++++++-- tests/test-fb-hgext-infinitepush-backup.t | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hgext/infinitepush/backupcommands.py b/hgext/infinitepush/backupcommands.py index a4a5991a70..260f7955fc 100644 --- a/hgext/infinitepush/backupcommands.py +++ b/hgext/infinitepush/backupcommands.py @@ -600,9 +600,14 @@ def _dobackup(ui, repo, dest, **opts): repo, newbookmarks, removedbookmarks, newheads, removedheads, namingmgr) - # Special case if backup state is empty. Clean all backup bookmarks from the - # server. + # Special cases if backup state is empty. if bkpstate.empty(): + # If there is nothing to backup, exit now to prevent accidentally + # clearing a previous backup. + if not afterbackuplocalbooks and not afterbackupheads: + ui.status(_('nothing to backup\n')) + return + # Otherwise, clean all backup bookmarks from the server. bookmarkstobackup[namingmgr.getbackupheadprefix()] = '' bookmarkstobackup[namingmgr.getbackupbookmarkprefix()] = '' diff --git a/tests/test-fb-hgext-infinitepush-backup.t b/tests/test-fb-hgext-infinitepush-backup.t index 8a8e424b6b..cb2d67c95b 100644 --- a/tests/test-fb-hgext-infinitepush-backup.t +++ b/tests/test-fb-hgext-infinitepush-backup.t @@ -26,7 +26,7 @@ Backup empty repo $ setup $ hg pushbackup starting backup .* (re) - finished in \d+\.(\d+)? seconds (re) + nothing to backup $ mkcommit commit $ hg prune . 0 files updated, 0 files merged, 1 files removed, 0 files unresolved @@ -51,6 +51,13 @@ Re-clone the client Setup client $ setup +Pushing in this new, empty clone shouldn't clear the old backup + $ hg pushbackup + starting backup .* (re) + nothing to backup + $ scratchbookmarks + infinitepush/backups/test/[0-9a-zA-Z.-]+\$TESTTMP/client/heads/606a357e69adb2e36d559ae3237626e82a955c9d 606a357e69adb2e36d559ae3237626e82a955c9d (re) + Make commit and backup it. Use lockfail.py to make sure lock is not taken during pushbackup $ mkcommit commit