@@ -329,6 +329,15 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
329
329
if progress is None :
330
330
progress = UpdateProgress ()
331
331
#END handle progress
332
+ prefix = ''
333
+ if dry_run :
334
+ prefix = "DRY-RUN: "
335
+ #END handle prefix
336
+
337
+ # to keep things plausible in dry-run mode
338
+ if dry_run :
339
+ mrepo = None
340
+ #END init mrepo
332
341
333
342
# ASSURE REPO IS PRESENT AND UPTODATE
334
343
#####################################
@@ -342,14 +351,16 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
342
351
op |= BEGIN
343
352
#END handle start
344
353
345
- progress .update (op , i , len_rmts , "Fetching remote %s" % remote )
354
+ progress .update (op , i , len_rmts , prefix + "Fetching remote %s of submodule %r " % ( remote , self . name ) )
346
355
#===============================
347
- remote .fetch (progress = progress )
356
+ if not dry_run :
357
+ remote .fetch (progress = progress )
358
+ #END handle dry-run
348
359
#===============================
349
360
if i == len_rmts - 1 :
350
361
op |= END
351
362
#END handle end
352
- progress .update (op , i , len_rmts , "Done fetching remote %s " % remote )
363
+ progress .update (op , i , len_rmts , prefix + "Done fetching remote of submodule %r " % self . name )
353
364
#END fetch new data
354
365
except InvalidGitRepositoryError :
355
366
if not init :
@@ -359,7 +370,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
359
370
360
371
# there is no git-repository yet - but delete empty paths
361
372
module_path = join_path_native (self .repo .working_tree_dir , self .path )
362
- if os .path .isdir (module_path ):
373
+ if not dry_run and os .path .isdir (module_path ):
363
374
try :
364
375
os .rmdir (module_path )
365
376
except OSError :
@@ -369,42 +380,51 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
369
380
370
381
# don't check it out at first - nonetheless it will create a local
371
382
# branch according to the remote-HEAD if possible
372
- progress .update (BEGIN | CLONE , 0 , 1 , "Cloning %s to %s" % (self .url , module_path ))
373
- mrepo = git .Repo .clone_from (self .url , module_path , n = True )
374
- progress .update (END | CLONE , 0 , 1 , "Done cloning to %s" % module_path )
383
+ progress .update (BEGIN | CLONE , 0 , 1 , prefix + "Cloning %s to %s in submodule %r" % (self .url , module_path , self .name ))
384
+ if not dry_run :
385
+ mrepo = git .Repo .clone_from (self .url , module_path , n = True )
386
+ #END handle dry-run
387
+ progress .update (END | CLONE , 0 , 1 , prefix + "Done cloning to %s" % module_path )
375
388
376
- # see whether we have a valid branch to checkout
377
- try :
378
- # find a remote which has our branch - we try to be flexible
379
- remote_branch = find_first_remote_branch (mrepo .remotes , self .branch_name )
380
- local_branch = mkhead (mrepo , self .branch_path )
381
-
382
- # have a valid branch, but no checkout - make sure we can figure
383
- # that out by marking the commit with a null_sha
384
- local_branch .set_object (util .Object (mrepo , self .NULL_BIN_SHA ))
385
- # END initial checkout + branch creation
386
-
387
- # make sure HEAD is not detached
388
- mrepo .head .set_reference (local_branch , logmsg = "submodule: attaching head to %s" % local_branch )
389
- mrepo .head .ref .set_tracking_branch (remote_branch )
390
- except IndexError :
391
- print >> sys .stderr , "Warning: Failed to checkout tracking branch %s" % self .branch_path
392
- #END handle tracking branch
393
389
394
- # NOTE: Have to write the repo config file as well, otherwise
395
- # the default implementation will be offended and not update the repository
396
- # Maybe this is a good way to assure it doesn't get into our way, but
397
- # we want to stay backwards compatible too ... . Its so redundant !
398
- self .repo .config_writer ().set_value (sm_section (self .name ), 'url' , self .url )
390
+ if not dry_run :
391
+ # see whether we have a valid branch to checkout
392
+ try :
393
+ # find a remote which has our branch - we try to be flexible
394
+ remote_branch = find_first_remote_branch (mrepo .remotes , self .branch_name )
395
+ local_branch = mkhead (mrepo , self .branch_path )
396
+
397
+ # have a valid branch, but no checkout - make sure we can figure
398
+ # that out by marking the commit with a null_sha
399
+ local_branch .set_object (util .Object (mrepo , self .NULL_BIN_SHA ))
400
+ # END initial checkout + branch creation
401
+
402
+ # make sure HEAD is not detached
403
+ mrepo .head .set_reference (local_branch , logmsg = "submodule: attaching head to %s" % local_branch )
404
+ mrepo .head .ref .set_tracking_branch (remote_branch )
405
+ except IndexError :
406
+ print >> sys .stderr , "Warning: Failed to checkout tracking branch %s" % self .branch_path
407
+ #END handle tracking branch
408
+
409
+ # NOTE: Have to write the repo config file as well, otherwise
410
+ # the default implementation will be offended and not update the repository
411
+ # Maybe this is a good way to assure it doesn't get into our way, but
412
+ # we want to stay backwards compatible too ... . Its so redundant !
413
+ self .repo .config_writer ().set_value (sm_section (self .name ), 'url' , self .url )
414
+ #END handle dry_run
399
415
#END handle initalization
400
416
401
417
402
418
# DETERMINE SHAS TO CHECKOUT
403
419
############################
404
420
binsha = self .binsha
405
421
hexsha = self .hexsha
406
- is_detached = mrepo .head .is_detached
407
- if to_latest_revision :
422
+ if mrepo is not None :
423
+ # mrepo is only set if we are not in dry-run mode or if the module existed
424
+ is_detached = mrepo .head .is_detached
425
+ #END handle dry_run
426
+
427
+ if not dry_run and to_latest_revision :
408
428
msg_base = "Cannot update to latest revision in repository at %r as " % mrepo .working_dir
409
429
if not is_detached :
410
430
rref = mrepo .head .ref .tracking_branch ()
@@ -421,29 +441,35 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
421
441
# END handle to_latest_revision option
422
442
423
443
# update the working tree
424
- if mrepo .head .commit .binsha != binsha :
425
- progress .update (BEGIN | UPDWKTREE , 0 , 1 , "Updating working tree at %s" % self .path )
426
- if is_detached :
427
- # NOTE: for now we force, the user is no supposed to change detached
428
- # submodules anyway. Maybe at some point this becomes an option, to
429
- # properly handle user modifications - see below for future options
430
- # regarding rebase and merge.
431
- mrepo .git .checkout (hexsha , force = True )
432
- else :
433
- # TODO: allow to specify a rebase, merge, or reset
434
- # TODO: Warn if the hexsha forces the tracking branch off the remote
435
- # branch - this should be prevented when setting the branch option
436
- mrepo .head .reset (hexsha , index = True , working_tree = True )
437
- # END handle checkout
438
- progress .update (END | UPDWKTREE , 0 , 1 , "Done updating working tree at %s" % self .path )
444
+ # handles dry_run
445
+ if mrepo is not None and mrepo .head .commit .binsha != binsha :
446
+ progress .update (BEGIN | UPDWKTREE , 0 , 1 , prefix + "Updating working tree at %s for submodule %r" % (self .path , self .name ))
447
+ if not dry_run :
448
+ if is_detached :
449
+ # NOTE: for now we force, the user is no supposed to change detached
450
+ # submodules anyway. Maybe at some point this becomes an option, to
451
+ # properly handle user modifications - see below for future options
452
+ # regarding rebase and merge.
453
+ mrepo .git .checkout (hexsha , force = True )
454
+ else :
455
+ # TODO: allow to specify a rebase, merge, or reset
456
+ # TODO: Warn if the hexsha forces the tracking branch off the remote
457
+ # branch - this should be prevented when setting the branch option
458
+ mrepo .head .reset (hexsha , index = True , working_tree = True )
459
+ # END handle checkout
460
+ #END handle dry_run
461
+ progress .update (END | UPDWKTREE , 0 , 1 , prefix + "Done updating working tree for submodule %r" % self .name )
439
462
# END update to new commit only if needed
440
463
441
464
# HANDLE RECURSION
442
465
##################
443
466
if recursive :
444
- for submodule in self .iter_items (self .module ()):
445
- submodule .update (recursive , init , to_latest_revision , progress = progress )
446
- # END handle recursive update
467
+ # in dry_run mode, the module might not exist
468
+ if mrepo is not None :
469
+ for submodule in self .iter_items (self .module ()):
470
+ submodule .update (recursive , init , to_latest_revision , progress = progress , dry_run = dry_run )
471
+ # END handle recursive update
472
+ #END handle dry run
447
473
# END for each submodule
448
474
449
475
return self
@@ -843,8 +869,7 @@ def config_reader(self):
843
869
def children (self ):
844
870
"""
845
871
:return: IterableList(Submodule, ...) an iterable list of submodules instances
846
- which are children of this submodule
847
- :raise InvalidGitRepositoryError: if the submodule is not checked-out"""
872
+ which are children of this submodule or 0 if the submodule is not checked out"""
848
873
return self ._get_intermediate_items (self )
849
874
850
875
#} END query interface
0 commit comments