@@ -190,14 +190,16 @@ def p4_has_move_command():
190190 # assume it failed because @... was invalid changelist
191191 return True
192192
193- def system (cmd ):
193+ def system (cmd , ignore_error = False ):
194194 expand = isinstance (cmd ,basestring )
195195 if verbose :
196196 sys .stderr .write ("executing %s\n " % str (cmd ))
197197 retcode = subprocess .call (cmd , shell = expand )
198- if retcode :
198+ if retcode and not ignore_error :
199199 raise CalledProcessError (retcode , cmd )
200200
201+ return retcode
202+
201203def p4_system (cmd ):
202204 """Specifically invoke p4 as the system command. """
203205 real_cmd = p4_build_cmd (cmd )
@@ -540,7 +542,12 @@ def p4Where(depotPath):
540542 return clientPath
541543
542544def 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 ()
544551
545552def isValidGitDir (path ):
546553 if (os .path .exists (path + "/HEAD" )
@@ -1649,18 +1656,17 @@ def exportGitTags(self, gitTags):
16491656 def run (self , args ):
16501657 if len (args ) == 0 :
16511658 self .master = currentGitBranch ()
1652- if len (self .master ) == 0 or not gitBranchExists ("refs/heads/%s" % self .master ):
1653- die ("Detecting current git branch failed!" )
16541659 elif len (args ) == 1 :
16551660 self .master = args [0 ]
16561661 if not branchExists (self .master ):
16571662 die ("Branch %s does not exist" % self .master )
16581663 else :
16591664 return False
16601665
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 )
16641670
16651671 [upstream , settings ] = findUpstreamBranchPoint ()
16661672 self .depotPath = settings ['depot-paths' ][0 ]
@@ -1728,7 +1734,12 @@ def run(self, args):
17281734 self .check ()
17291735
17301736 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 )]):
17321743 commits .append (line .strip ())
17331744 commits .reverse ()
17341745
0 commit comments