Skip to content

Commit c2cbb30

Browse files
committed
Merge branch 'ld/p4-current-branch-fix'
"git p4" used "name-rev HEAD" when it wants to learn what branch is checked out; it should use "symbolic-ref HEAD". * ld/p4-current-branch-fix: git-p4: don't use name-rev to get current branch git-p4: add read_pipe_text() internal function git-p4: add failing test for name-rev rather than symbolic-ref
2 parents 442136f + eff4511 commit c2cbb30

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

git-p4.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,42 @@ def p4_write_pipe(c, stdin):
160160
real_cmd = p4_build_cmd(c)
161161
return write_pipe(real_cmd, stdin)
162162

163-
def read_pipe(c, ignore_error=False):
163+
def read_pipe_full(c):
164+
""" Read output from command. Returns a tuple
165+
of the return status, stdout text and stderr
166+
text.
167+
"""
164168
if verbose:
165169
sys.stderr.write('Reading pipe: %s\n' % str(c))
166170

167171
expand = isinstance(c,basestring)
168172
p = subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=expand)
169173
(out, err) = p.communicate()
170-
if p.returncode != 0 and not ignore_error:
171-
die('Command failed: %s\nError: %s' % (str(c), err))
174+
return (p.returncode, out, err)
175+
176+
def read_pipe(c, ignore_error=False):
177+
""" Read output from command. Returns the output text on
178+
success. On failure, terminates execution, unless
179+
ignore_error is True, when it returns an empty string.
180+
"""
181+
(retcode, out, err) = read_pipe_full(c)
182+
if retcode != 0:
183+
if ignore_error:
184+
out = ""
185+
else:
186+
die('Command failed: %s\nError: %s' % (str(c), err))
172187
return out
173188

189+
def read_pipe_text(c):
190+
""" Read output from a command with trailing whitespace stripped.
191+
On error, returns None.
192+
"""
193+
(retcode, out, err) = read_pipe_full(c)
194+
if retcode != 0:
195+
return None
196+
else:
197+
return out.rstrip()
198+
174199
def p4_read_pipe(c, ignore_error=False):
175200
real_cmd = p4_build_cmd(c)
176201
return read_pipe(real_cmd, ignore_error)
@@ -577,12 +602,7 @@ def p4Where(depotPath):
577602
return clientPath
578603

579604
def currentGitBranch():
580-
retcode = system(["git", "symbolic-ref", "-q", "HEAD"], ignore_error=True)
581-
if retcode != 0:
582-
# on a detached head
583-
return None
584-
else:
585-
return read_pipe(["git", "name-rev", "HEAD"]).split(" ")[1].strip()
605+
return read_pipe_text(["git", "symbolic-ref", "--short", "-q", "HEAD"])
586606

587607
def isValidGitDir(path):
588608
return git_dir(path) != None

t/t9807-git-p4-submit.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ test_expect_success 'submit with master branch name from argv' '
139139
)
140140
'
141141

142+
test_expect_success 'allow submit from branch with same revision but different name' '
143+
test_when_finished cleanup_git &&
144+
git p4 clone --dest="$git" //depot &&
145+
(
146+
cd "$git" &&
147+
test_commit "file8" &&
148+
git checkout -b branch1 &&
149+
git checkout -b branch2 &&
150+
git config git-p4.skipSubmitEdit true &&
151+
git config git-p4.allowSubmit "branch1" &&
152+
test_must_fail git p4 submit &&
153+
git checkout branch1 &&
154+
git p4 submit
155+
)
156+
'
157+
142158
#
143159
# Basic submit tests, the five handled cases
144160
#

0 commit comments

Comments
 (0)