add hg cloud status command

Summary: implement "hg cloud status" command

Reviewed By: mitrandir77

Differential Revision: D15738154

fbshipit-source-id: 774562d726c0f03d89d3b06696794e129668816f
This commit is contained in:
Mohammad Ayoub 2019-06-13 05:49:48 -07:00 committed by Facebook Github Bot
parent 7a090c3975
commit 48c061efcc
4 changed files with 85 additions and 3 deletions

View File

@ -648,7 +648,6 @@ def cloudsync(ui, repo, cloudrefs=None, dest=None, **opts):
with backuplock.lock(repo):
ret = sync.sync(repo, remotepath, getconnection, cloudrefs, full, version)
background.backgroundbackupother(repo, dest=dest)
return ret
@ -776,6 +775,33 @@ def backupdisable(ui, repo, **opts):
return 0
@subcmd("status")
def cloudstatus(ui, repo, **opts):
"""Shows information about the state of the user's workspace"""
workspacename = workspace.currentworkspace(repo)
if workspacename is None:
ui.write(_("You are not connected to any workspace\n"))
return
autosync = "ON" if background.autobackupenabled(repo) else "OFF"
currentsyncstate = syncstate.SyncState(repo, workspacename)
syncupdatetime = time.ctime(currentsyncstate.lastupdatetime)
if repo.localvfs.isfile("lastsync.log"):
state = repo.localvfs.read("lastsync.log")
else:
state = "Not logged"
ui.write(
_(
"Workspace: %s\n"
"Automatic Sync: %s\n"
"Last Sync: %s\n"
"Last Sync State: %s\n"
)
% (workspacename, autosync, syncupdatetime, state)
)
@command("debugwaitbackup", [("", "timeout", "", "timeout value")])
def waitbackup(ui, repo, timeout):
"""wait for backup operations to complete"""

View File

@ -169,6 +169,14 @@ def sync(
# Check that Scm Service is running and a subscription exists
subscription.SubscriptionManager(repo).checksubscription()
# log whether the sync was successful
with repo.wlock():
fp = repo.localvfs("lastsync.log", "w+")
if synced and not failed:
fp.write("Success")
else:
fp.write("Failed")
fp.close()
return _maybeupdateworkingcopy(repo, startnode)

View File

@ -292,4 +292,3 @@ show as backed up if '--hidden' is passed.
note: 2 changesets are not backed up.
(run 'hg cloud backup' to perform a backup)
(if this fails, please report to the Source Control Team)

View File

@ -91,11 +91,24 @@ Joining:
(your repo is not connected to any workspace)
(use 'hg cloud join --help' for more details)
[255]
Run cloud status before setting any workspace
$ hg cloud status
You are not connected to any workspace
$ hg cloud join -w feature
commitcloud: this repository is now connected to the 'user/test/feature' workspace for the 'server' repo
commitcloud: synchronizing 'server' with 'user/test/feature'
commitcloud: commits synchronized
finished in * (glob)
Run cloud status after setting a workspace
$ hg cloud status
Workspace: user/test/feature
Automatic Sync: OFF
Last Sync: * (glob)
Last Sync State: Success
$ hg cloud leave
commitcloud: this repository is now disconnected from commit cloud
$ hg cloud join
@ -126,6 +139,36 @@ Joining:
$ cd ..
Run cloud status after setting workspace
$ cd client1
$ hg cloud status
Workspace: user/test/default
Automatic Sync: OFF
Last Sync: * (glob)
Last Sync State: Success
Enable autosync
$ setconfig infinitepushbackup.autobackup=true
Run cloud status after enabling autosync
$ hg cloud status
Workspace: user/test/default
Automatic Sync: ON
Last Sync: * (glob)
Last Sync State: Success
Disable autosync
$ setconfig infinitepushbackup.autobackup=false
Run cloud status after disabling autosync
$ hg cloud status
Workspace: user/test/default
Automatic Sync: OFF
Last Sync: * (glob)
Last Sync State: Success
$ cd ..
Make a commit in the first client, and sync it
$ cd client1
$ mkcommit "commit1"
@ -823,6 +866,13 @@ Simulate failure to backup a commit by setting the server maxbundlesize limit ve
commitcloud: failed to synchronize 2 commits
finished in * (glob)
Run cloud status after failing to synchronize
$ hg cloud status
Workspace: user/test/default
Automatic Sync: OFF
Last Sync: * (glob)
Last Sync State: Failed
$ hg cloud check -r .
9bd68ef10d6bdb8ebf3273a7b91bc4f3debe2a87 not backed up
@ -1209,4 +1259,3 @@ Rejoin
|/
o d20a80d4def3 'base'