patchbomb: check that targets exist at the publicurl
authorPierre-Yves David <pierre-yves.david@fb.com>
Sun, 11 Oct 2015 22:13:03 -0700
changeset 26626 dca161728dc9
parent 26625 adae8928fe09
child 26627 832c98d79587
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.
hgext/patchbomb.py
tests/test-patchbomb.t
--- a/hgext/patchbomb.py	Mon Oct 12 20:13:12 2015 +0200
+++ b/hgext/patchbomb.py	Sun Oct 11 22:13:03 2015 -0700
@@ -527,6 +527,37 @@
     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)
--- a/tests/test-patchbomb.t	Mon Oct 12 20:13:12 2015 +0200
+++ b/tests/test-patchbomb.t	Sun Oct 11 22:13:03 2015 -0700
@@ -2845,15 +2845,34 @@
 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]