diff --git a/hgext/commitcloud/__init__.py b/hgext/commitcloud/__init__.py index cdbb472a5a..6046637fff 100644 --- a/hgext/commitcloud/__init__.py +++ b/hgext/commitcloud/__init__.py @@ -66,8 +66,17 @@ # %i is substituted with the user identity scm_daemon_log_path = /path/to/%i/logfile - # Use secrets_tool for token + # Use secrets_tool for token backup between machines use_secrets_tool = true + + # Default workspace only! Take into account user's only commits + # This includes all the stacks where at least one commit is user's own + # Caution: using this option may leave some local commits unbacked up + user_commits_only = true + + # Default workspace only! Take into account only custom set of commits + # Caution: using this option may leave some local commits unbacked up + custom_push_revs = draft() """ from __future__ import absolute_import diff --git a/hgext/commitcloud/commitcloudcommands.py b/hgext/commitcloud/commitcloudcommands.py index 2f9ad8ad0a..4fd7ba0ee2 100644 --- a/hgext/commitcloud/commitcloudcommands.py +++ b/hgext/commitcloud/commitcloudcommands.py @@ -453,6 +453,26 @@ def _docloudsync(ui, repo, checkbackedup=False, cloudrefs=None, **opts): if cloudrefs is None: cloudrefs = serv.getreferences(reponame, workspace, lastsyncstate.version) + # apply config setting to filter heads client code will include + # in 'new heads' to send to the server, + # this allows `cloud sync` works with some extra + # local only unbacked up commits on any machine + if not opts.get("push_revs") and ( + workspace == getdefaultrepoworkspace(ui, repo)[1] + ): + pushrevs = "" + + if ui.configbool("commitcloud", "user_commits_only"): + pushrevs += " & author(%s)" % util.emailuser(ui.username()) + + if ui.config("commitcloud", "custom_push_revs"): + pushrevs += " & (%s)" % ui.config("commitcloud", "custom_push_revs") + + if pushrevs: + opts["push_revs"] = ["draft() " + pushrevs] + + revspec = opts.get("push_revs") + synced = False pushfailures = set() while not synced: @@ -463,7 +483,6 @@ def _docloudsync(ui, repo, checkbackedup=False, cloudrefs=None, **opts): localbookmarks = _getbookmarks(repo) obsmarkers = commitcloudutil.getsyncingobsmarkers(repo) - revspec = opts.get("push_revs") if revspec: revs = scmutil.revrange(repo, revspec) pushheads = [ctx.hex() for ctx in repo.set("heads(%ld::)", revs)] @@ -693,12 +712,15 @@ def _update(ui, repo, destination): def _filterpushside(ui, repo, pushheads, localheads, lastsyncstateheads): """filter push side to include only the specified push heads to the delta""" - if pushheads: - listmsg = _("except with heads '%s' ") % ", ".join([ph[:6] for ph in pushheads]) - else: - listmsg = "" + # local - allowed - synced + skipped = set(localheads) - set(pushheads) - set(lastsyncstateheads) + if skipped: + highlightstatus( + ui, + _("push filter: the stacks with heads '%s' are not included in the sync\n") + % ", ".join([ph[:6] for ph in skipped]), + ) - highlightstatus(ui, _("all unsynced stacks are skipped %s\n") % listmsg) return list(set(localheads) & (set(lastsyncstateheads) | set(pushheads))) diff --git a/tests/test-fb-hgext-commitcloud-sync.t b/tests/test-fb-hgext-commitcloud-sync.t index f9fce7b708..b85c2546f9 100644 --- a/tests/test-fb-hgext-commitcloud-sync.t +++ b/tests/test-fb-hgext-commitcloud-sync.t @@ -235,7 +235,6 @@ Try to push selectively $ hg cloud sync --push-revs '.' #commitcloud synchronizing 'server' with 'user/test/default' - #commitcloud all unsynced stacks are skipped except with heads '48610b' backing up stack rooted at a7bb357e7299 remote: pushing 2 commits: remote: a7bb357e7299 commit1 amended @@ -244,7 +243,6 @@ Try to push selectively $ hg cloud sync --push-revs 48610b1a7ec0 #commitcloud synchronizing 'server' with 'user/test/default' - #commitcloud all unsynced stacks are skipped except with heads '48610b' #commitcloud commits synchronized $ hg cloud sync