{"thread":{"id":"8821","subject":"[StGIT PATCH] Recognize refs under remotes/ as parent branch on stack creation.","startedAt":"2007-07-02T21:37:44Z","lastAt":"2007-07-02T21:37:44Z","messageCount":1,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"46283","messageId":"20070702213744.3014.793.stgit@gandelf.nowhere.earth","threadId":"8821","inReplyTo":null,"subject":"[StGIT PATCH] Recognize refs under remotes/ as parent branch on stack creation.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-07-02T21:37:44Z","receivedAt":"2007-07-02T21:37:44Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Also remove the \"relaxed\" parentbranch detecting logic (accepting\nanything with an embedded slash as a parent branch name), which was\nnever invoked because of a bug, and looks like a bad idea anyway.\nBetter add sensible namespaces when we feel a need for them, rather\nthan accepting anything by default, with potentially unwanted results.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/branch.py |   37 +++++++++++++++++++++++--------------\n 1 files changed, 23 insertions(+), 14 deletions(-)\n\ndiff --git a/stgit/commands/branch.py b/stgit/commands/branch.py\nindex c22e143..e45bcee 100644\n--- a/stgit/commands/branch.py\n+++ b/stgit/commands/branch.py\n@@ -122,27 +122,36 @@ def func(parser, options, args):\n \n         tree_id = None\n         if len(args) >= 2:\n+            parentbranch = None\n             try:\n-                if git.rev_parse(args[1]) == git.rev_parse('refs/heads/' + args[1]):\n-                    # we are for sure referring to a branch\n-                    parentbranch = 'refs/heads/' + args[1]\n-                    out.info('Recording \"%s\" as parent branch' % parentbranch)\n-                elif git.rev_parse(args[1]) and re.search('/', args[1]):\n-                    # FIXME: should the test be more strict ?\n-                    parentbranch = args[1]\n-                else:\n-                    # Note: this includes refs to StGIT patches\n-                    out.info('Don\\'t know how to determine parent branch'\n-                             ' from \"%s\"' % args[1])\n-                    parentbranch = None\n+                branchpoint = git.rev_parse(args[1])\n+\n+                # first, look for branchpoint in well-known branch namespaces\n+                for namespace in ('refs/heads/', 'remotes/'):\n+                    # check if branchpoint exists in namespace\n+                    try:\n+                        maybehead = git.rev_parse(namespace + args[1])\n+                    except git.GitException:\n+                        maybehead = None\n+\n+                    # check if git resolved branchpoint to this namespace\n+                    if maybehead and branchpoint == maybehead:\n+                        # we are for sure referring to a branch\n+                        parentbranch = namespace + args[1]\n+\n             except git.GitException:\n                 # should use a more specific exception to catch only\n                 # non-git refs ?\n                 out.info('Don\\'t know how to determine parent branch'\n                          ' from \"%s\"' % args[1])\n-                parentbranch = None\n \n-            tree_id = git_id(args[1])\n+            tree_id = branchpoint or git_id(args[1])\n+\n+            if parentbranch:\n+                out.info('Recording \"%s\" as parent branch' % parentbranch)\n+            else:\n+                out.info('Don\\'t know how to determine parent branch'\n+                         ' from \"%s\"' % args[1])                \n         else:\n             # branch stack off current branch\n             parentbranch = git.get_head_file()\n"}]}