diff hggit/git_handler.py @ 820:0d6d2fcc62b6

git_handler: support wildcards for Git branch name matching This is quite similar to syntax Git supports. In the future maybe core Mercurial could be extended to support this, but I think this independently makes sense in hg-git.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 31 Oct 2014 11:14:35 -0700
parents 826296785e8b
children 53e7e8f34dcd
line wrap: on
line diff
--- a/hggit/git_handler.py	Fri Oct 31 10:46:56 2014 -0700
+++ b/hggit/git_handler.py	Fri Oct 31 11:14:35 2014 -0700
@@ -1055,13 +1055,20 @@
                 (r, r[r.find('/', r.find('/')+1)+1:])
                     for r in refs]
             for h in heads:
-                r = [pair[0] for pair in stripped_refs if pair[1] == h]
-                if not r:
-                    raise hgutil.Abort("ref %s not found on remote server" % h)
-                elif len(r) == 1:
-                    filteredrefs.append(r[0])
+                if h.endswith('/*'):
+                    prefix = h[:-1]  # include the / but not the *
+                    r = [pair[0] for pair in stripped_refs
+                         if pair[1].startswith(prefix)]
+                    r.sort()
+                    filteredrefs.extend(r)
                 else:
-                    raise hgutil.Abort("ambiguous reference %s: %r" % (h, r))
+                    r = [pair[0] for pair in stripped_refs if pair[1] == h]
+                    if not r:
+                        raise hgutil.Abort("ref %s not found on remote server" % h)
+                    elif len(r) == 1:
+                        filteredrefs.append(r[0])
+                    else:
+                        raise hgutil.Abort("ambiguous reference %s: %r" % (h, r))
         else:
             for ref, sha in refs.iteritems():
                 if (not ref.endswith('^{}')