Skip to content

Commit eff4511

Browse files
luked99gitster
authored andcommitted
git-p4: don't use name-rev to get current branch
git-p4 was using "git name-rev" to find out the current branch. That is not safe, since if multiple branches or tags point at the same revision, the result obtained might not be what is expected. Instead use "git symbolic-ref". Signed-off-by: Luke Diamand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78871bf commit eff4511

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

git-p4.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,7 @@ def p4Where(depotPath):
602602
return clientPath
603603

604604
def currentGitBranch():
605-
retcode = system(["git", "symbolic-ref", "-q", "HEAD"], ignore_error=True)
606-
if retcode != 0:
607-
# on a detached head
608-
return None
609-
else:
610-
return read_pipe(["git", "name-rev", "HEAD"]).split(" ")[1].strip()
605+
return read_pipe_text(["git", "symbolic-ref", "--short", "-q", "HEAD"])
611606

612607
def isValidGitDir(path):
613608
return git_dir(path) != None

t/t9807-git-p4-submit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ test_expect_success 'submit with master branch name from argv' '
139139
)
140140
'
141141

142-
test_expect_failure 'allow submit from branch with same revision but different name' '
142+
test_expect_success 'allow submit from branch with same revision but different name' '
143143
test_when_finished cleanup_git &&
144144
git p4 clone --dest="$git" //depot &&
145145
(

0 commit comments

Comments
 (0)