Project

General

Profile

Bug #5167

git-pbchk fails to detect parent branch

Added by Garrett D'Amore about 5 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Category:
tools - gate/build tools
Start date:
2014-09-15
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:

Description

There is a bug in git-pbchk in that it attempts to pass whitespace to Popen() instead of using an array. Furthermore the splitting logic is busted.

Here's my solution, which uses the list form of submission to git() (thereby avoiding the busted format), and doing the split properly by using a scratch array to receive the split(), then checking the results.

--- /opt/onbld/bin/git-pbchk    Mon Sep 15 11:13:27 2014
+++ /tank/garrett/illumos/usr/src/tools/scripts/git-pbchk.py    Tue Jul 22 09:41:14 2014
@@ -122,8 +122,8 @@
     if not branch:
         return None

-    p = git(["for-each-ref", "--format=%(refname:short) %(upstream:short)",
-            "refs/heads/"])
+    p = git("for-each-ref --format=%(refname:short) %(upstream:short) " +
+            "refs/heads/")

     if not p:
         sys.stderr.write("Failed finding git parent branch\\n")
@@ -130,9 +130,9 @@
         sys.exit(err)

     for line in p:
-    arr = line.split()
-    if len(arr) > 1:
-            local, remote = arr[0], arr[1]
+        # Git 1.7 will leave a ' ' trailing any non-tracking branch
+        if ' ' in line and not line.endswith(' \\n'):
+            local, remote = line.split()
             if local == branch:
                 return remote
     return 'origin/master'

Related issues

Has duplicate illumos gate - Bug #7128: git-pbchk fails to detect parent branchClosed2016-06-23

Actions

History

#1

Updated by Garrett D'Amore about 5 years ago

Sorry, that was a "reverse" diff. Let's get it in the right direction:

garrett@proteus{27}> diff -u  /tank/garrett/illumos/usr/src/tools/scripts/git-pbchk.py /opt/onbld/bin/git-pbchk    
--- /tank/garrett/illumos/usr/src/tools/scripts/git-pbchk.py    Tue Jul 22 09:41:14 2014
+++ /opt/onbld/bin/git-pbchk    Mon Sep 15 11:13:27 2014
@@ -122,8 +122,8 @@
     if not branch:
         return None

-    p = git("for-each-ref --format=%(refname:short) %(upstream:short) " +
-            "refs/heads/")
+    p = git(["for-each-ref", "--format=%(refname:short) %(upstream:short)",
+            "refs/heads/"])

     if not p:
         sys.stderr.write("Failed finding git parent branch\\n")
@@ -130,9 +130,9 @@
         sys.exit(err)

     for line in p:
-        # Git 1.7 will leave a ' ' trailing any non-tracking branch
-        if ' ' in line and not line.endswith(' \\n'):
-            local, remote = line.split()
+    arr = line.split()
+    if len(arr) > 1:
+            local, remote = arr[0], arr[1]
             if local == branch:
                 return remote
     return 'origin/master'
#2

Updated by Yuri Pankov over 2 years ago

  • Subject changed from git-pbchk fails when parent is not origin/master to git-pbchk fails to detect parent branch
  • Status changed from New to In Progress
  • Assignee set to Hans Rosenfeld
  • % Done changed from 0 to 50
  • Difficulty changed from Medium to Bite-size
  • Tags deleted (needs-triage)

hijacking the ticket to cherry-pick fix from illumos-nexenta.

#3

Updated by Electric Monk over 2 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 50 to 100

git commit 28e2b3ad0b14867ee7f3383890f6658e6e9448a1

commit  28e2b3ad0b14867ee7f3383890f6658e6e9448a1
Author: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Date:   2017-07-04T21:32:17.000Z

    5167 git-pbchk fails to detect parent branch
    Reviewed by: Dan Fields <dan.fields@nexenta.com>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Approved by: Robert Mustacchi <rm@joyent.com>

#4

Updated by Yuri Pankov about 2 years ago

  • Has duplicate Bug #7128: git-pbchk fails to detect parent branch added

Also available in: Atom PDF