@@ -672,7 +672,7 @@ def move(self, module_path, configuration=True, module=True):
672
672
return self
673
673
674
674
@unbare_repo
675
- def remove (self ,module = True ,force = False ,configuration = True ,dry_run = False ):
675
+ def remove (self ,module = True ,force = False ,configuration = True ,dry_run = False , _is_recursive = False ):
676
676
"""Remove this submodule from the repository. This will remove our entry
677
677
from the .gitmodules file and the entry in the .git/config file.
678
678
@@ -705,7 +705,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
705
705
706
706
# Recursively remove children of this submodule
707
707
for csm in self .children ():
708
- csm .remove (module ,force ,configuration ,dry_run )
708
+ csm .remove (module ,force ,configuration ,dry_run , _is_recursive = True )
709
709
del (csm )
710
710
# end
711
711
@@ -772,7 +772,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
772
772
# END delete tree if possible
773
773
# END handle force
774
774
775
- if os .path .isdir (git_dir ):
775
+ if not dry_run and os .path .isdir (git_dir ):
776
776
rmtree (git_dir )
777
777
# end handle separate bare repository
778
778
# END handle module deletion
@@ -781,22 +781,28 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
781
781
######################
782
782
if configuration and not dry_run :
783
783
# first the index-entry
784
- index = self .repo .index
784
+ parent_index = self .repo .index
785
785
try :
786
- del (index .entries [index .entry_key (self .path ,0 )])
786
+ del (parent_index .entries [parent_index .entry_key (self .path ,0 )])
787
787
except KeyError :
788
788
pass
789
789
# END delete entry
790
- index .write ()
790
+ parent_index .write ()
791
791
792
792
# now git config - need the config intact, otherwise we can't query
793
- #inforamtion anymore
793
+ #information anymore
794
794
writer = self .repo .config_writer ()
795
795
writer .remove_section (sm_section (self .name ))
796
796
writer .release ()
797
797
writer = self .config_writer ()
798
798
writer .remove_section ()
799
799
writer .release ()
800
+
801
+ # Assure we don't leave the parent repository in a dirty state, and commit our changes
802
+ # It's important for recursive, unforced, deletions to work as expected
803
+ if _is_recursive :
804
+ self .module ().index .commit ("Removed submodule '%s'" % self .name )
805
+ # end
800
806
# END delete configuration
801
807
802
808
# void our data not to delay invalid access