mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
enable switching from a draft commit possible for most of cases
Summary: enable switching from a draft commit possible for most of the cases make it possible if the public root of the current commit is an ancestor of the main bookmark this condition we need because the remote bookmarks can be different for different workspaces and they define phases I think it will cover most of workflows Reviewed By: mitrandir77 Differential Revision: D25780999 fbshipit-source-id: b1c25b29a7668d51244ca43d6b0c30fa2fc068d9
This commit is contained in:
parent
d50939b1de
commit
19b20b43a1
@ -15,6 +15,7 @@ from edenscm.mercurial import (
|
||||
cmdutil,
|
||||
error,
|
||||
extensions,
|
||||
hg,
|
||||
hintutil,
|
||||
lock as lockmod,
|
||||
node as nodemod,
|
||||
@ -234,23 +235,38 @@ def cloudjoin(ui, repo, **opts):
|
||||
with backuplock.lock(repo), repo.wlock(), repo.lock(), repo.transaction(
|
||||
"commit cloud switch workspace clean up transaction"
|
||||
) as tr:
|
||||
# check uncommitted changes
|
||||
if any(repo.status()):
|
||||
raise error.Abort(
|
||||
_(
|
||||
"this repository can not be switched to the '%s' workspace due to uncommitted changes"
|
||||
)
|
||||
% workspacename
|
||||
)
|
||||
# enforce the precondition that working directory must be clean
|
||||
cmdutil.bailifchanged(repo)
|
||||
|
||||
# check that the current location is a public commit
|
||||
if repo["."].mutable():
|
||||
raise error.Abort(
|
||||
_(
|
||||
"this repository can not be switched to the '%s' workspace\n"
|
||||
"please update your location to a public commit first"
|
||||
# * get the public root of the current commit
|
||||
# * get the "main" bookmark that represents the main commit history
|
||||
# * if the root is an ancestor of that bookmark, then update to it (the commit will be public in dst workspace)
|
||||
currentnode = repo["."]
|
||||
newnode = currentnode
|
||||
while newnode.mutable():
|
||||
newnode = newnode.parents()[0]
|
||||
|
||||
publicroot = newnode
|
||||
mainbookmark = bookmarksmod.mainbookmark(repo)
|
||||
mainbookmarknode = repo[mainbookmark]
|
||||
if repo.changelog.isancestor(
|
||||
publicroot.node(), mainbookmarknode.node()
|
||||
):
|
||||
hg.update(repo, newnode, False)
|
||||
ui.status(
|
||||
_("working directory now at %s\n")
|
||||
% ui.label(str(publicroot), "node")
|
||||
)
|
||||
else:
|
||||
raise error.Abort(
|
||||
_(
|
||||
"this repository can not be switched to the '%s' workspace\n"
|
||||
"please update your location to a public commit first like `hg up %s`"
|
||||
)
|
||||
% (workspacename, mainbookmark)
|
||||
)
|
||||
% workspacename
|
||||
)
|
||||
# remove heads and bookmarks before connecting to a new workspace
|
||||
visibility.setvisibleheads(repo, [])
|
||||
# remove all local bookmarks
|
||||
|
@ -87,30 +87,14 @@ Switch workspace to the same workspace
|
||||
commitcloud: commits synchronized
|
||||
finished in * (glob)
|
||||
|
||||
Switch workspace from a draft commit
|
||||
Switch workspace from a draft commit that is an ancestor of a main bookmark
|
||||
$ hg cloud join --switch -w w2
|
||||
commitcloud: synchronizing 'server' with 'user/test/w1'
|
||||
commitcloud: commits synchronized
|
||||
finished in * (glob)
|
||||
commitcloud: now this repository will be switched from the 'user/test/w1' to the 'user/test/w2' workspace
|
||||
abort: this repository can not be switched to the 'user/test/w2' workspace
|
||||
please update your location to a public commit first
|
||||
[255]
|
||||
$ showgraph
|
||||
@ B (W1): draft
|
||||
│
|
||||
o A (W1): draft
|
||||
│
|
||||
o base: public remote/master
|
||||
|
||||
Switch workspace from a public commit
|
||||
$ hg up d20a80d4def3
|
||||
0 files updated, 0 files merged, 2 files removed, 0 files unresolved
|
||||
$ hg cloud join --switch -w w2
|
||||
commitcloud: synchronizing 'server' with 'user/test/w1'
|
||||
commitcloud: commits synchronized
|
||||
finished in * (glob)
|
||||
commitcloud: now this repository will be switched from the 'user/test/w1' to the 'user/test/w2' workspace
|
||||
working directory now at d20a80d4def3
|
||||
commitcloud: this repository is now connected to the 'user/test/w2' workspace for the 'server' repo
|
||||
commitcloud: synchronizing 'server' with 'user/test/w2'
|
||||
pulling dff058cfb955 from ssh://user@dummy/server
|
||||
@ -319,7 +303,7 @@ Try to switch with uncommitted changes
|
||||
commitcloud: commits synchronized
|
||||
finished in * (glob)
|
||||
commitcloud: now this repository will be switched from the 'user/test/3' to the 'user/test/w1' workspace
|
||||
abort: this repository can not be switched to the 'user/test/w1' workspace due to uncommitted changes
|
||||
abort: uncommitted changes
|
||||
[255]
|
||||
|
||||
Commit changes to be able to switch
|
||||
|
Loading…
Reference in New Issue
Block a user