@@ -190,14 +190,16 @@ def p4_has_move_command():
190
190
# assume it failed because @... was invalid changelist
191
191
return True
192
192
193
- def system (cmd ):
193
+ def system (cmd , ignore_error = False ):
194
194
expand = isinstance (cmd ,basestring )
195
195
if verbose :
196
196
sys .stderr .write ("executing %s\n " % str (cmd ))
197
197
retcode = subprocess .call (cmd , shell = expand )
198
- if retcode :
198
+ if retcode and not ignore_error :
199
199
raise CalledProcessError (retcode , cmd )
200
200
201
+ return retcode
202
+
201
203
def p4_system (cmd ):
202
204
"""Specifically invoke p4 as the system command. """
203
205
real_cmd = p4_build_cmd (cmd )
@@ -540,7 +542,12 @@ def p4Where(depotPath):
540
542
return clientPath
541
543
542
544
def currentGitBranch ():
543
- return read_pipe ("git name-rev HEAD" ).split (" " )[1 ].strip ()
545
+ retcode = system (["git" , "symbolic-ref" , "-q" , "HEAD" ], ignore_error = True )
546
+ if retcode != 0 :
547
+ # on a detached head
548
+ return None
549
+ else :
550
+ return read_pipe (["git" , "name-rev" , "HEAD" ]).split (" " )[1 ].strip ()
544
551
545
552
def isValidGitDir (path ):
546
553
if (os .path .exists (path + "/HEAD" )
@@ -1649,18 +1656,17 @@ def exportGitTags(self, gitTags):
1649
1656
def run (self , args ):
1650
1657
if len (args ) == 0 :
1651
1658
self .master = currentGitBranch ()
1652
- if len (self .master ) == 0 or not gitBranchExists ("refs/heads/%s" % self .master ):
1653
- die ("Detecting current git branch failed!" )
1654
1659
elif len (args ) == 1 :
1655
1660
self .master = args [0 ]
1656
1661
if not branchExists (self .master ):
1657
1662
die ("Branch %s does not exist" % self .master )
1658
1663
else :
1659
1664
return False
1660
1665
1661
- allowSubmit = gitConfig ("git-p4.allowSubmit" )
1662
- if len (allowSubmit ) > 0 and not self .master in allowSubmit .split ("," ):
1663
- die ("%s is not in git-p4.allowSubmit" % self .master )
1666
+ if self .master :
1667
+ allowSubmit = gitConfig ("git-p4.allowSubmit" )
1668
+ if len (allowSubmit ) > 0 and not self .master in allowSubmit .split ("," ):
1669
+ die ("%s is not in git-p4.allowSubmit" % self .master )
1664
1670
1665
1671
[upstream , settings ] = findUpstreamBranchPoint ()
1666
1672
self .depotPath = settings ['depot-paths' ][0 ]
@@ -1728,7 +1734,12 @@ def run(self, args):
1728
1734
self .check ()
1729
1735
1730
1736
commits = []
1731
- for line in read_pipe_lines (["git" , "rev-list" , "--no-merges" , "%s..%s" % (self .origin , self .master )]):
1737
+ if self .master :
1738
+ commitish = self .master
1739
+ else :
1740
+ commitish = 'HEAD'
1741
+
1742
+ for line in read_pipe_lines (["git" , "rev-list" , "--no-merges" , "%s..%s" % (self .origin , commitish )]):
1732
1743
commits .append (line .strip ())
1733
1744
commits .reverse ()
1734
1745
0 commit comments