summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/objects/submodule/base.py20
-rw-r--r--git/test/test_submodule.py11
2 files changed, 20 insertions, 11 deletions
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index ee10aa7d..15ba8a0d 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -672,7 +672,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
return self
@unbare_repo
- def remove(self, module=True, force=False, configuration=True, dry_run=False):
+ def remove(self, module=True, force=False, configuration=True, dry_run=False, _is_recursive=False):
"""Remove this submodule from the repository. This will remove our entry
from the .gitmodules file and the entry in the .git/config file.
@@ -705,7 +705,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
# Recursively remove children of this submodule
for csm in self.children():
- csm.remove(module, force, configuration, dry_run)
+ csm.remove(module, force, configuration, dry_run, _is_recursive=True)
del(csm)
# end
@@ -772,7 +772,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
# END delete tree if possible
# END handle force
- if os.path.isdir(git_dir):
+ if not dry_run and os.path.isdir(git_dir):
rmtree(git_dir)
# end handle separate bare repository
# END handle module deletion
@@ -781,22 +781,28 @@ class Submodule(util.IndexObject, Iterable, Traversable):
######################
if configuration and not dry_run:
# first the index-entry
- index = self.repo.index
+ parent_index = self.repo.index
try:
- del(index.entries[index.entry_key(self.path, 0)])
+ del(parent_index.entries[parent_index.entry_key(self.path, 0)])
except KeyError:
pass
# END delete entry
- index.write()
+ parent_index.write()
# now git config - need the config intact, otherwise we can't query
- # inforamtion anymore
+ # information anymore
writer = self.repo.config_writer()
writer.remove_section(sm_section(self.name))
writer.release()
writer = self.config_writer()
writer.remove_section()
writer.release()
+
+ # Assure we don't leave the parent repository in a dirty state, and commit our changes
+ # It's important for recursive, unforced, deletions to work as expected
+ if _is_recursive:
+ self.module().index.commit("Removed submodule '%s'" % self.name)
+ # end
# END delete configuration
# void our data not to delay invalid access
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index 76412123..ace7ab07 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -666,9 +666,12 @@ class TestSubmodule(TestBase):
# remove
sm_module_path = sm.module().git_dir
- sm.remove()
- assert not sm.exists()
- assert not sm.module_exists()
- assert not os.path.isdir(sm_module_path)
+
+ for dry_run in (True, False):
+ sm.remove(dry_run=dry_run)
+ assert sm.exists() == dry_run
+ assert sm.module_exists() == dry_run
+ assert os.path.isdir(sm_module_path) == dry_run
+ # end for each dry-run mode