@@ -362,6 +362,11 @@ def isValidGitDir(path):
362
362
def parseRevision (ref ):
363
363
return read_pipe ("git rev-parse %s" % ref ).strip ()
364
364
365
+ def branchExists (ref ):
366
+ rev = read_pipe (["git" , "rev-parse" , "-q" , "--verify" , ref ],
367
+ ignore_error = True )
368
+ return len (rev ) > 0
369
+
365
370
def extractLogMessageFromGitCommit (commit ):
366
371
logMessage = ""
367
372
@@ -1089,6 +1094,8 @@ class P4Submit(Command, P4UserMap):
1089
1094
die ("Detecting current git branch failed!" )
1090
1095
elif len (args ) == 1 :
1091
1096
self .master = args [0 ]
1097
+ if not branchExists (self .master ):
1098
+ die ("Branch %s does not exist" % self .master )
1092
1099
else :
1093
1100
return False
1094
1101
@@ -1951,7 +1958,10 @@ class P4Sync(Command, P4UserMap):
1951
1958
if not gitBranchExists (self .refPrefix + "HEAD" ) and self .importIntoRemotes and gitBranchExists (self .branch ):
1952
1959
system ("git symbolic-ref %sHEAD %s" % (self .refPrefix , self .branch ))
1953
1960
1954
- if self .useClientSpec or gitConfig ("git-p4.useclientspec" ) == "true" :
1961
+ if not self .useClientSpec :
1962
+ if gitConfig ("git-p4.useclientspec" , "--bool" ) == "true" :
1963
+ self .useClientSpec = True
1964
+ if self .useClientSpec :
1955
1965
self .getClientSpec ()
1956
1966
1957
1967
# TODO: should always look at previous commits,
@@ -2024,6 +2034,17 @@ class P4Sync(Command, P4UserMap):
2024
2034
revision = ""
2025
2035
self .users = {}
2026
2036
2037
+ # Make sure no revision specifiers are used when --changesfile
2038
+ # is specified.
2039
+ bad_changesfile = False
2040
+ if len (self .changesFile ) > 0 :
2041
+ for p in self .depotPaths :
2042
+ if p .find ("@" ) >= 0 or p .find ("#" ) >= 0 :
2043
+ bad_changesfile = True
2044
+ break
2045
+ if bad_changesfile :
2046
+ die ("Option --changesfile is incompatible with revision specifiers" )
2047
+
2027
2048
newPaths = []
2028
2049
for p in self .depotPaths :
2029
2050
if p .find ("@" ) != - 1 :
@@ -2040,7 +2061,10 @@ class P4Sync(Command, P4UserMap):
2040
2061
revision = p [hashIdx :]
2041
2062
p = p [:hashIdx ]
2042
2063
elif self .previousDepotPaths == []:
2043
- revision = "#head"
2064
+ # pay attention to changesfile, if given, else import
2065
+ # the entire p4 tree at the head revision
2066
+ if len (self .changesFile ) == 0 :
2067
+ revision = "#head"
2044
2068
2045
2069
p = re .sub ("\.\.\.$" , "" , p )
2046
2070
if not p .endswith ("/" ):
@@ -2335,7 +2359,8 @@ def main():
2335
2359
args = sys .argv [2 :]
2336
2360
2337
2361
if len (options ) > 0 :
2338
- options .append (optparse .make_option ("--git-dir" , dest = "gitdir" ))
2362
+ if cmd .needsGit :
2363
+ options .append (optparse .make_option ("--git-dir" , dest = "gitdir" ))
2339
2364
2340
2365
parser = optparse .OptionParser (cmd .usage .replace ("%prog" , "%prog " + cmdName ),
2341
2366
options ,
@@ -2365,6 +2390,7 @@ def main():
2365
2390
2366
2391
if not cmd .run (args ):
2367
2392
parser .print_help ()
2393
+ sys .exit (2 )
2368
2394
2369
2395
2370
2396
if __name__ == '__main__' :
0 commit comments