mirror of
https://github.com/facebook/sapling.git
synced 2024-12-28 15:44:27 +03:00
add undelete workspace command
Summary: The command is needed to restore a deleted workspace Reviewed By: markbt Differential Revision: D23250376 fbshipit-source-id: e24a7cbc0aad004291853b4c34d7474789aa9c2b
This commit is contained in:
parent
e72b4988d3
commit
56e9cd9ed7
@ -274,8 +274,8 @@ class BaseService(pycompat.ABC):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def archiveworkspace(self, reponame, workspace):
|
||||
"""Archive the given workspace
|
||||
def updateworkspacearchive(self, reponame, workspace, archive):
|
||||
"""Archive or Restore the given workspace
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
|
@ -819,6 +819,10 @@ def cloudlistworspaces(ui, repo, **opts):
|
||||
"run `hg cloud join -w <workspace name> --switch` to switch to a different workspace\n"
|
||||
)
|
||||
)
|
||||
if activeonly and archived:
|
||||
ui.status(
|
||||
_("run `hg cloud list --all` to list all workspaces, including deleted\n")
|
||||
)
|
||||
|
||||
|
||||
@subcmd("deleteworkspace|delete", [] + workspace.workspaceopts)
|
||||
@ -842,14 +846,31 @@ def clouddeleteworkspace(ui, repo, **opts):
|
||||
return
|
||||
|
||||
reponame = ccutil.getreponame(repo)
|
||||
service.get(ui, tokenmod.TokenLocator(ui).token).archiveworkspace(
|
||||
reponame, workspacename
|
||||
service.get(ui, tokenmod.TokenLocator(ui).token).updateworkspacearchive(
|
||||
reponame, workspacename, True
|
||||
)
|
||||
ui.status(
|
||||
_("workspace %s has been deleted\n") % workspacename, component="commitcloud"
|
||||
)
|
||||
|
||||
|
||||
@subcmd("undeleteworkspace|undelete", [] + workspace.workspaceopts)
|
||||
def cloudundeleteworkspace(ui, repo, **opts):
|
||||
"""Restore (unarchive) workspace in commit cloud"""
|
||||
|
||||
workspacename = workspace.parseworkspace(ui, opts)
|
||||
if workspacename is None:
|
||||
raise error.Abort(_("workspace name should be provided\n"))
|
||||
|
||||
reponame = ccutil.getreponame(repo)
|
||||
service.get(ui, tokenmod.TokenLocator(ui).token).updateworkspacearchive(
|
||||
reponame, workspacename, False
|
||||
)
|
||||
ui.status(
|
||||
_("workspace %s has been restored\n") % workspacename, component="commitcloud"
|
||||
)
|
||||
|
||||
|
||||
@subcmd(
|
||||
"listbackups",
|
||||
[
|
||||
|
@ -512,15 +512,15 @@ class _HttpsCommitCloudService(baseservice.BaseService):
|
||||
workspaces = response["workspaces_data"]
|
||||
return self._makeworkspacesinfo(workspaces)
|
||||
|
||||
@perftrace.tracefunc("Archive Workspace")
|
||||
def archiveworkspace(self, reponame, workspace):
|
||||
"""Archive the given workspace
|
||||
@perftrace.tracefunc("Archive/Restore Workspace")
|
||||
def updateworkspacearchive(self, reponame, workspace, archived):
|
||||
"""Archive or Restore the given workspace
|
||||
"""
|
||||
self.ui.debug(
|
||||
"sending 'update_workspace_archive' request\n", component="commitcloud"
|
||||
)
|
||||
path = "/commit_cloud/update_workspace_archive"
|
||||
data = {"repo_name": reponame, "workspace": workspace, "archived": True}
|
||||
data = {"repo_name": reponame, "workspace": workspace, "archived": archived}
|
||||
start = util.timer()
|
||||
response = self._send(path, data)
|
||||
elapsed = util.timer() - start
|
||||
|
@ -283,7 +283,9 @@ class _LocalService(baseservice.BaseService):
|
||||
)
|
||||
)
|
||||
|
||||
def archiveworkspace(self, reponame, workspace):
|
||||
def updateworkspacearchive(self, reponame, workspace, archived):
|
||||
"""Archive or Restore the given workspace
|
||||
"""
|
||||
allworkspaces = self.getworkspaces(reponame, None)
|
||||
found = next(
|
||||
(winfo for winfo in allworkspaces if winfo.name == workspace), None
|
||||
@ -297,7 +299,7 @@ class _LocalService(baseservice.BaseService):
|
||||
if found:
|
||||
allworkspaces.append(
|
||||
baseservice.WorkspaceInfo(
|
||||
name=found.name, archived=True, version=found.version
|
||||
name=found.name, archived=archived, version=found.version
|
||||
)
|
||||
)
|
||||
else:
|
||||
|
@ -43,6 +43,7 @@ workspaces:
|
||||
default
|
||||
run `hg cloud sl -w <workspace name>` to view the commits
|
||||
run `hg cloud join -w <workspace name> --switch` to switch to a different workspace
|
||||
run `hg cloud list --all` to list all workspaces, including deleted
|
||||
"""
|
||||
|
||||
sh % "hg cloud list --all" == r"""
|
||||
@ -76,3 +77,29 @@ sh % "hg cloud list" == r"""
|
||||
commitcloud: searching workspaces for the 'server' repo
|
||||
no active workspaces found with the prefix user/test/
|
||||
"""
|
||||
|
||||
sh % "hg cloud undelete -w default" == r"""
|
||||
commitcloud: workspace user/test/default has been restored
|
||||
"""
|
||||
|
||||
sh % "hg cloud list" == r"""
|
||||
commitcloud: searching workspaces for the 'server' repo
|
||||
workspaces:
|
||||
default
|
||||
run `hg cloud sl -w <workspace name>` to view the commits
|
||||
run `hg cloud join -w <workspace name> --switch` to switch to a different workspace
|
||||
run `hg cloud list --all` to list all workspaces, including deleted
|
||||
"""
|
||||
|
||||
sh % "hg cloud undelete -w old" == r"""
|
||||
commitcloud: workspace user/test/old has been restored
|
||||
"""
|
||||
|
||||
sh % "hg cloud list" == r"""
|
||||
commitcloud: searching workspaces for the 'server' repo
|
||||
workspaces:
|
||||
default
|
||||
old
|
||||
run `hg cloud sl -w <workspace name>` to view the commits
|
||||
run `hg cloud join -w <workspace name> --switch` to switch to a different workspace
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user