@@ -853,12 +853,14 @@ def __init__(self):
853
853
# preserve the user, requires relevant p4 permissions
854
854
optparse .make_option ("--preserve-user" , dest = "preserveUser" , action = "store_true" ),
855
855
optparse .make_option ("--export-labels" , dest = "exportLabels" , action = "store_true" ),
856
+ optparse .make_option ("--dry-run" , "-n" , dest = "dry_run" , action = "store_true" ),
856
857
]
857
858
self .description = "Submit changes from git to the perforce depot."
858
859
self .usage += " [name of git branch to submit into perforce depot]"
859
860
self .origin = ""
860
861
self .detectRenames = False
861
862
self .preserveUser = gitConfig ("git-p4.preserveUser" ).lower () == "true"
863
+ self .dry_run = False
862
864
self .isWindows = (platform .system () == "Windows" )
863
865
self .exportLabels = False
864
866
self .p4HasMoveCommand = p4_has_command ("move" )
@@ -1366,14 +1368,17 @@ def exportGitTags(self, gitTags):
1366
1368
for mapping in clientSpec .mappings :
1367
1369
labelTemplate += "\t %s\n " % mapping .depot_side .path
1368
1370
1369
- p4_write_pipe (["label" , "-i" ], labelTemplate )
1371
+ if self .dry_run :
1372
+ print "Would create p4 label %s for tag" % name
1373
+ else :
1374
+ p4_write_pipe (["label" , "-i" ], labelTemplate )
1370
1375
1371
- # Use the label
1372
- p4_system (["tag" , "-l" , name ] +
1373
- ["%s@%s" % (mapping .depot_side .path , changelist ) for mapping in clientSpec .mappings ])
1376
+ # Use the label
1377
+ p4_system (["tag" , "-l" , name ] +
1378
+ ["%s@%s" % (mapping .depot_side .path , changelist ) for mapping in clientSpec .mappings ])
1374
1379
1375
- if verbose :
1376
- print "created p4 label for tag %s" % name
1380
+ if verbose :
1381
+ print "created p4 label for tag %s" % name
1377
1382
1378
1383
def run (self , args ):
1379
1384
if len (args ) == 0 :
@@ -1432,12 +1437,15 @@ def run(self, args):
1432
1437
os .makedirs (self .clientPath )
1433
1438
1434
1439
chdir (self .clientPath )
1435
- print "Synchronizing p4 checkout..."
1436
- if new_client_dir :
1437
- # old one was destroyed, and maybe nobody told p4
1438
- p4_sync ("..." , "-f" )
1440
+ if self .dry_run :
1441
+ print "Would synchronize p4 checkout in %s" % self .clientPath
1439
1442
else :
1440
- p4_sync ("..." )
1443
+ print "Synchronizing p4 checkout..."
1444
+ if new_client_dir :
1445
+ # old one was destroyed, and maybe nobody told p4
1446
+ p4_sync ("..." , "-f" )
1447
+ else :
1448
+ p4_sync ("..." )
1441
1449
self .check ()
1442
1450
1443
1451
commits = []
@@ -1488,10 +1496,17 @@ def run(self, args):
1488
1496
# Apply the commits, one at a time. On failure, ask if should
1489
1497
# continue to try the rest of the patches, or quit.
1490
1498
#
1499
+ if self .dry_run :
1500
+ print "Would apply"
1491
1501
applied = []
1492
1502
last = len (commits ) - 1
1493
1503
for i , commit in enumerate (commits ):
1494
- ok = self .applyCommit (commit )
1504
+ if self .dry_run :
1505
+ print " " , read_pipe (["git" , "show" , "-s" ,
1506
+ "--format=format:%h %s" , commit ])
1507
+ ok = True
1508
+ else :
1509
+ ok = self .applyCommit (commit )
1495
1510
if ok :
1496
1511
applied .append (commit )
1497
1512
else :
@@ -1515,7 +1530,9 @@ def run(self, args):
1515
1530
1516
1531
chdir (self .oldWorkingDirectory )
1517
1532
1518
- if len (commits ) == len (applied ):
1533
+ if self .dry_run :
1534
+ pass
1535
+ elif len (commits ) == len (applied ):
1519
1536
print "All commits applied!"
1520
1537
1521
1538
sync = P4Sync ()
0 commit comments