Yuya Nishihara  committed bf28ee4

checksubrepo: ability to warn if tip of subrepo not referecend from tip of parent

  • Participants
  • Parent commits f3a4fd9

Comments (0)

Files changed (1)


-"""Check validity of .hgsubstate
+"""Check subrepo validity and common mistakes
+    # validate nodeid before accepting changesets
     pretxnchangegroup.checksubrepo = python:hghooks.checksubrepo.hook
+    # warn if tip of subrepo is not referenced by tip of parent
+    changegroup.checksubrepo = python:hghooks.checksubrepo.hook
+    outgoing.checksubrepo = python:hghooks.checksubrepo.hook
 import os
 from mercurial import hg, error, subrepo
                               ' not exists in sub repository <%s>'
                               % (rev[:12], path))
+def checktiprev(ui, repo):
+    for path, (src, rev, kind) in substate(repo['tip'], ui).iteritems():
+        # only supports relative hg subrepos
+        if path != src or kind != 'hg':
+            continue
+        srepo = hg.repository(ui, os.path.join(repo.root, src))
+        if srepo['tip'].hex() != rev:
+            ui.warn('tip of sub repository <%s> is not referenced from tip '
+                    'of parent\n' % path)
 def substate(ctx, ui):
         return subrepo.state(ctx, ui)
         firstnode = kwargs['node']
         for rev in xrange(repo[firstnode].rev(), len(repo)):
             checksubstate(ui, repo, substate(repo[rev], ui))
+    elif hooktype in ('changegroup', 'outgoing'):
+        checktiprev(ui, repo)
         ui.warn('unexpected hooktype: %s\n' % hooktype)