snapshot: prohibit regular checkout on snapshot

Differential Revision: D17093630

fbshipit-source-id: 4425c90fbdecfa3edc9f34f677e0be6b771aa0af
This commit is contained in:
Aleksei Kulikov 2019-09-04 11:07:35 -07:00 committed by Facebook Github Bot
parent 27055ce83b
commit c193470431
2 changed files with 33 additions and 0 deletions

View File

@ -14,6 +14,12 @@ for working with full snapshots of the working copy,
including the untracked files and unresolved merge artifacts.
TODO(alexeyqu): finish docs
Configs::
[ui]
# Allow to run `hg checkout` for snapshot revisions
allow-checkout-snapshot = False
"""
import hashlib
@ -41,6 +47,10 @@ cmdtable = {}
command = registrar.command(cmdtable)
lfs = None
configtable = {}
configitem = registrar.configitem(configtable)
configitem("ui", "allow-checkout-snapshot", default=False)
def extsetup(ui):
global lfs
@ -49,6 +59,24 @@ def extsetup(ui):
except KeyError:
raise error.Abort(_("snapshot extension requires lfs to be enabled\n"))
extensions.wrapfunction(hg, "updaterepo", _updaterepo)
def _updaterepo(orig, repo, node, overwrite, **opts):
allowsnapshots = repo.ui.configbool("ui", "allow-checkout-snapshot")
unfi = repo.unfiltered()
if not allowsnapshots and node in unfi:
ctx = unfi[node]
if "snapshotmetadataid" in ctx.extra():
raise error.Abort(
_(
"%s is a snapshot, set ui.allow-checkout-snapshot"
" config to True to checkout on it\n"
)
% ctx
)
return orig(repo, node, overwrite, **opts)
@command("snapshot", [], "SUBCOMMAND ...", subonly=True)
def snapshot(ui, repo, *args, **opts):

View File

@ -263,6 +263,11 @@
? untrackedfile
# Check out on the snapshot -- negative tests
# Regular checkout
$ hg checkout --hidden "$OID"
abort: aaa7692160b6 is a snapshot, set ui.allow-checkout-snapshot config to True to checkout on it
[255]
# Non-empty WC state
$ hg snapshot checkout "$OID"
abort: You must have a clean working copy to checkout on a snapshot. Use --force to bypass that.