# HG changeset patch # User Pierre-Yves David # Date 2015-10-12 05:13:03 # Node ID dca161728dc9a2df8de293a7df600606cdd1b208 # Parent adae8928fe095f2fefd0cd91024cbb083f69ca92 patchbomb: check that targets exist at the publicurl Advertising that the patch are available to be pulled requires that to be true. So we check revision availability on the remote before sending any email. diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -527,6 +527,37 @@ def patchbomb(ui, repo, *revs, **opts): if bundle: opts['revs'] = [str(r) for r in revs] + # check if revision exist on the public destination + publicurl = repo.ui.config('patchbomb', 'publicurl') + if publicurl is not None: + repo.ui.debug('checking that revision exist in the public repo') + try: + publicpeer = hg.peer(repo, {}, publicurl) + except error.RepoError: + repo.ui.write_err(_('unable to access public repo: %s\n') + % publicurl) + raise + if not publicpeer.capable('known'): + repo.ui.debug('skipping existence checks: public repo too old') + else: + out = [repo[r] for r in revs] + known = publicpeer.known(h.node() for h in out) + missing = [] + for idx, h in enumerate(out): + if not known[idx]: + missing.append(h) + if missing: + if 1 < len(missing): + msg = _('public "%s" is missing %s and %i others') + msg %= (publicurl, missing[0], len(missing) - 1) + else: + msg = _('public url %s is missing %s') + msg %= (publicurl, missing[0]) + revhint = ''.join('-r %s' % h + for h in repo.set('heads(%ld)', missing)) + hint = _('use "hg push %s %s"') % (publicurl, revhint) + raise error.Abort(msg, hint=hint) + # start if date: start_time = util.parsedate(date) diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t --- a/tests/test-patchbomb.t +++ b/tests/test-patchbomb.t @@ -2845,15 +2845,34 @@ single rev Test pull url header ================================= +basic version + $ echo 'intro=auto' >> $HGRCPATH - $ echo 'publicurl=http://example.com/myrepo/' >> $HGRCPATH + $ echo "publicurl=$TESTTMP/t2" >> $HGRCPATH $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' | grep '^#' - # HG changeset patch - # User test - # Date 5 0 - # Thu Jan 01 00:00:05 1970 +0000 - # Branch test - # Node ID 3b6f1ec9dde933a40a115a7990f8b320477231af - # Parent 2f9fa9b998c5fe3ac2bd9a2b14bfcbeecbc7c268 - # Available At http://example.com/myrepo/ - # hg pull http://example.com/myrepo/ -r 3b6f1ec9dde9 + abort: public url $TESTTMP/t2 is missing 3b6f1ec9dde9 + (use "hg push $TESTTMP/t2 -r 3b6f1ec9dde9") + [1] + +remote missing + + $ echo 'publicurl=$TESTTMP/missing' >> $HGRCPATH + $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' + unable to access public repo: $TESTTMP/missing + abort: repository $TESTTMP/missing not found! + [255] + +node missing at remote + + $ hg clone -r '9' . ../t3 + adding changesets + adding manifests + adding file changes + added 3 changesets with 3 changes to 3 files + updating to branch test + 3 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ echo 'publicurl=$TESTTMP/t3' >> $HGRCPATH + $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' + abort: public url $TESTTMP/t3 is missing 3b6f1ec9dde9 + (use "hg push $TESTTMP/t3 -r 3b6f1ec9dde9") + [255]