diff --git a/edenscm/hgext/commitcloud/commands.py b/edenscm/hgext/commitcloud/commands.py index 17a73067fa..91262afc13 100644 --- a/edenscm/hgext/commitcloud/commands.py +++ b/edenscm/hgext/commitcloud/commands.py @@ -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""" diff --git a/edenscm/hgext/commitcloud/sync.py b/edenscm/hgext/commitcloud/sync.py index 473491e0f2..c163903768 100644 --- a/edenscm/hgext/commitcloud/sync.py +++ b/edenscm/hgext/commitcloud/sync.py @@ -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) diff --git a/tests/test-commitcloud-backup-status.t b/tests/test-commitcloud-backup-status.t index f4fe2bf672..5b4f1546dc 100644 --- a/tests/test-commitcloud-backup-status.t +++ b/tests/test-commitcloud-backup-status.t @@ -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) - diff --git a/tests/test-commitcloud-sync.t b/tests/test-commitcloud-sync.t index 641add661f..9f92600411 100644 --- a/tests/test-commitcloud-sync.t +++ b/tests/test-commitcloud-sync.t @@ -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' -