@@ -672,7 +672,7 @@ def move(self, module_path, configuration=True, module=True):
672672return self
673673
674674@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 ):
676676"""Remove this submodule from the repository. This will remove our entry
677677 from the .gitmodules file and the entry in the .git/config file.
678678
@@ -705,7 +705,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
705705
706706# Recursively remove children of this submodule
707707for csm in self .children ():
708- csm .remove (module ,force ,configuration ,dry_run )
708+ csm .remove (module ,force ,configuration ,dry_run , _is_recursive = True )
709709del (csm )
710710# end
711711
@@ -772,7 +772,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
772772# END delete tree if possible
773773# END handle force
774774
775- if os .path .isdir (git_dir ):
775+ if not dry_run and os .path .isdir (git_dir ):
776776rmtree (git_dir )
777777# end handle separate bare repository
778778# END handle module deletion
@@ -781,22 +781,28 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
781781######################
782782if configuration and not dry_run :
783783# first the index-entry
784- index = self .repo .index
784+ parent_index = self .repo .index
785785try :
786- del (index .entries [index .entry_key (self .path ,0 )])
786+ del (parent_index .entries [parent_index .entry_key (self .path ,0 )])
787787except KeyError :
788788pass
789789# END delete entry
790- index .write ()
790+ parent_index .write ()
791791
792792# now git config - need the config intact, otherwise we can't query
793- #inforamtion anymore
793+ #information anymore
794794writer = self .repo .config_writer ()
795795writer .remove_section (sm_section (self .name ))
796796writer .release ()
797797writer = self .config_writer ()
798798writer .remove_section ()
799799writer .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
800806# END delete configuration
801807
802808# void our data not to delay invalid access