89
89
90
90
# verbose logging
91
91
verbose = False
92
+ very_verbose = False
92
93
93
94
94
95
# Logging and output
@@ -160,6 +161,9 @@ def pquery(command, stdin=None, **kwargs):
160
161
161
162
stdout , _ = proc .communicate (stdin )
162
163
164
+ if very_verbose :
165
+ print str (stdout ).strip ()
166
+
163
167
if proc .returncode != 0 :
164
168
raise ProcessException (proc .returncode , command [0 ], ' ' .join (command ), os .getcwd ())
165
169
@@ -249,18 +253,21 @@ def remove(file):
249
253
def commit ():
250
254
popen ([hg_cmd , 'commit' ] + (['-v' ] if verbose else ['-q' ]))
251
255
252
- def push (repo , all = None ):
256
+ def publish (repo , all = None ):
253
257
popen ([hg_cmd , 'push' ] + (['--new-branch' ] if all else []) + (['-v' ] if verbose else ['-q' ]))
254
258
255
- def pull (repo ):
259
+ def fetch (repo ):
260
+ log ("Pulling remote repository \" %s\" to local \" %s\" " % (repo .url , repo .name ))
256
261
popen ([hg_cmd , 'pull' ] + (['-v' ] if verbose else ['-q' ]))
257
262
263
+ def checkout (repo , hash = None , clean = False ):
264
+ log ("Checkout \" %s\" to %s" % (repo .name , repo .hashtype (hash , True )))
265
+ popen ([hg_cmd , 'update' ] + (['-r' , hash ] if hash else []) + (['-C' ] if clean else []) + (['-v' ] if verbose else ['-q' ]))
266
+
258
267
def update (repo , hash = None , clean = False ):
259
268
if not repo .is_local :
260
- log ("Pulling remote repository \" %s\" to local \" %s\" " % (repo .url , repo .name ))
261
- popen ([hg_cmd , 'pull' ] + (['-v' ] if verbose else ['-q' ]))
262
- log ("Updating \" %s\" to %s" % (repo .name , repo .hashtype (hash , True )))
263
- popen ([hg_cmd , 'update' ] + (['-r' , hash ] if hash else []) + (['-C' ] if clean else []) + (['-v' ] if verbose else ['-q' ]))
269
+ Hg .fetch (repo )
270
+ Hg .checkout (repo , hash , clean )
264
271
265
272
def status ():
266
273
return pquery ([hg_cmd , 'status' ] + (['-v' ] if verbose else ['-q' ]))
@@ -434,7 +441,7 @@ def remove(file):
434
441
def commit ():
435
442
popen ([git_cmd , 'commit' , '-a' ] + (['-v' ] if verbose else ['-q' ]))
436
443
437
- def push (repo , all = None ):
444
+ def publish (repo , all = None ):
438
445
if all :
439
446
popen ([git_cmd , 'push' , '--all' ] + (['-v' ] if verbose else ['-q' ]))
440
447
else :
@@ -443,32 +450,45 @@ def push(repo, all=None):
443
450
if remote and branch :
444
451
popen ([git_cmd , 'push' , remote , branch ] + (['-v' ] if verbose else ['-q' ]))
445
452
else :
446
- err = "Unable to push outgoing changes for \" %s\" in \" %s\" .\n " % (repo .name , repo .path )
453
+ err = "Unable to publish outgoing changes for \" %s\" in \" %s\" .\n " % (repo .name , repo .path )
447
454
if not remote :
448
- error (err + "The local repository is not associated with a remote one.\n " , 1 )
455
+ error (err + "The local repository is not associated with a remote one." , 1 )
449
456
if not branch :
450
- error (err + "Working set is not on a branch.\n " , 1 )
457
+ error (err + "Working set is not on a branch." , 1 )
451
458
452
-
453
- def pull ( repo ):
459
+ def fetch ( repo ):
460
+ log ( "Fetching remote repository \" %s \" to local \" %s \" " % ( repo . url , repo . name ))
454
461
popen ([git_cmd , 'fetch' , '--all' ] + (['-v' ] if verbose else ['-q' ]))
455
462
463
+ def discard (repo ):
464
+ log ("Discarding local changes in \" %s\" " % repo .name )
465
+ popen ([git_cmd , 'reset' , 'HEAD' ] + ([] if verbose else ['-q' ])) # unmarks files for commit
466
+ popen ([git_cmd , 'checkout' , '.' ] + ([] if verbose else ['-q' ])) # undo modified files
467
+ popen ([git_cmd , 'clean' , '-fdq' ] + ([] if verbose else ['-q' ])) # cleans up untracked files and folders
468
+
469
+ def checkout (repo , hash = None , clean = False ):
470
+ log ("Checkout \" %s\" to %s" % (repo .name , repo .hashtype (hash , True )))
471
+ popen ([git_cmd , 'checkout' , hash ] + ([] if verbose else ['-q' ]))
472
+
456
473
def update (repo , hash = None , clean = False ):
457
474
if clean :
458
- log ("Discarding local changes in \" %s\" " % repo .name )
459
- popen ([git_cmd , 'reset' , 'HEAD' ] + ([] if verbose else ['-q' ])) # unmarks files for commit
460
- popen ([git_cmd , 'checkout' , '.' ] + ([] if verbose else ['-q' ])) # undo modified files
461
- popen ([git_cmd , 'clean' , '-fdq' ] + ([] if verbose else ['-q' ])) # cleans up untracked files and folders
475
+ Git .discard (repo )
476
+ if not repo .is_local :
477
+ Git .fetch (repo )
462
478
if hash :
463
- if not repo .is_local :
464
- log ("Fetching remote repository \" %s\" to local \" %s\" " % (repo .url , repo .name ))
465
- popen ([git_cmd , 'fetch' , '-v' , '--all' ] + (['-v' ] if verbose else ['-q' ]))
466
- log ("Updating \" %s\" to %s" % (repo .name , repo .hashtype (hash , True )))
467
- popen ([git_cmd , 'checkout' ] + [hash ] + ([] if verbose else ['-q' ]))
479
+ Git .checkout (repo , hash , clean )
468
480
else :
469
- if not repo .is_local :
470
- log ("Fetching remote repository \" %s\" to local \" %s\" and updating to latest revision in the current branch" % (repo .url , repo .name ))
471
- popen ([git_cmd , 'pull' , '--all' ] + (['-v' ] if verbose else ['-q' ]))
481
+ remote = Git .getremote ()
482
+ branch = Git .getbranch ()
483
+ if remote and branch :
484
+ log ("Merging \" %s\" with remote branch %s/%s from \" %s\" " % (repo .name , remote , branch , repo .url ))
485
+ popen ([git_cmd , 'merge' , "%s/%s" % (remote , branch )] + (['-v' ] if verbose else ['-q' ]))
486
+ else :
487
+ err = "Unable to update \" %s\" in \" %s\" .\n " % (repo .name , repo .path )
488
+ if not remote :
489
+ log (err + "The local repository is not associated with a remote one." )
490
+ if not branch :
491
+ log (err + "Working set is not on a branch." )
472
492
473
493
def status ():
474
494
return pquery ([git_cmd , 'status' , '-s' ] + (['-v' ] if verbose else []))
@@ -495,7 +515,7 @@ def outgoing():
495
515
# Check if remote branch exists
496
516
if not pquery ([git_cmd , 'rev-parse' , '%s/%s' % (remote , branch )]):
497
517
return 1
498
- except ProcessException as e :
518
+ except ProcessException :
499
519
return 1
500
520
501
521
# Check for outgoing commits for the same remote branch
@@ -991,6 +1011,7 @@ def subcommand(command):
991
1011
subparser .add_argument (* opt , ** arg )
992
1012
993
1013
subparser .add_argument ("-v" , "--verbose" , action = "store_true" , dest = "verbose" , help = "Verbose diagnostic output" )
1014
+ subparser .add_argument ("-vv" , "--very_verbose" , action = "store_true" , dest = "very_verbose" , help = "Very verbose diagnostic output" )
994
1015
995
1016
def thunk (parsed_args ):
996
1017
argv = [arg ['dest' ] if 'dest' in arg else arg ['name' ] for arg in args ]
@@ -1182,14 +1203,14 @@ def publish(all=None, top=True):
1182
1203
1183
1204
if repo .scm .dirty ():
1184
1205
action ("Uncommitted changes in %s \" %s\" in \" %s\" " % (repo .pathtype (repo .path ), repo .name , repo .path ))
1185
- raw_input ('Press enter to commit and push : ' )
1206
+ raw_input ('Press enter to commit and publish : ' )
1186
1207
repo .scm .commit ()
1187
1208
1188
1209
try :
1189
1210
outgoing = repo .scm .outgoing ()
1190
1211
if outgoing > 0 :
1191
1212
action ("Pushing local repository \" %s\" to remote \" %s\" " % (repo .name , repo .url ))
1192
- repo .scm .push (repo , all )
1213
+ repo .scm .publish (repo , all )
1193
1214
except ProcessException as e :
1194
1215
if e [0 ] != 1 :
1195
1216
raise e
@@ -1552,7 +1573,8 @@ def toolchain_(name=None):
1552
1573
status = 1
1553
1574
1554
1575
try :
1555
- verbose = args .verbose
1576
+ very_verbose = args .very_verbose
1577
+ verbose = very_verbose or args .verbose
1556
1578
log ('Working path \" %s\" (%s)' % (os .getcwd (), cwd_type ))
1557
1579
status = args .command (args )
1558
1580
except ProcessException as e :
0 commit comments