chiark / gitweb /
Correctly identify the parent branch (bug #10014)
authorCatalin Marinas <catalin.marinas@gmail.com>
Mon, 3 Dec 2007 10:30:20 +0000 (10:30 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Mon, 3 Dec 2007 10:30:20 +0000 (10:30 +0000)
Any valid git ref was identified as a possible parent branch. This patch
adds a check for the refs listed by git-show-ref.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/branch.py

index 87239315ec776106f4c45f724959699b521f4b37..dd021039ec3013e11f9172f294cdc851936a2024 100644 (file)
@@ -18,7 +18,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os, time
+import sys, os, time, re
 from optparse import OptionParser, make_option
 
 from stgit.commands.common import *
@@ -120,19 +120,15 @@ def func(parser, options, args):
             try:
                 branchpoint = git.rev_parse(args[1])
 
-                # first, look for branchpoint in well-known branch namespaces
-                for namespace in ('refs/heads/', 'remotes/'):
-                    # check if branchpoint exists in namespace
-                    try:
-                        maybehead = git.rev_parse(namespace + args[1])
-                    except git.GitException:
-                        maybehead = None
-
-                    # check if git resolved branchpoint to this namespace
-                    if maybehead and branchpoint == maybehead:
-                        # we are for sure referring to a branch
-                        parentbranch = namespace + args[1]
-
+                # parent branch?
+                head_re = re.compile('refs/(heads|remotes)/')
+                ref_re = re.compile(args[1] + '$')
+                for ref in git.all_refs():
+                    if head_re.match(ref) and ref_re.search(ref):
+                        # args[1] is a valid ref from the branchpoint
+                        # setting above
+                        parentbranch = args[1]
+                        break;
             except git.GitException:
                 # should use a more specific exception to catch only
                 # non-git refs ?