diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-01-19 17:04:50 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-01-19 17:04:50 +0100 |
commit | aaa84341f876927b545abdc674c811d60af00561 (patch) | |
tree | b4d286989570f1775b52a24a9f5503bf398fed6d | |
parent | 20863cfe4a1b0c5bea18677470a969073570e41c (diff) | |
download | gitpython-aaa84341f876927b545abdc674c811d60af00561.tar.gz |
Submodule.move() will auto-rename the submodule if the name was equal to the path
Fixes #238
-rw-r--r-- | git/objects/submodule/base.py | 6 | ||||
-rw-r--r-- | git/test/test_submodule.py | 5 |
2 files changed, 10 insertions, 1 deletions
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index f5ff457d..285d2423 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -675,6 +675,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): # rename the index entry - have to manipulate the index directly as # git-mv cannot be used on submodules ... yeah + previous_sm_path = self.path try: if configuration: try: @@ -701,6 +702,11 @@ class Submodule(util.IndexObject, Iterable, Traversable): raise # END handle undo rename + # Auto-rename submodule if it's name was 'default', that is, the checkout directory + if previous_sm_path == self.name: + self.rename(module_checkout_path) + # end + return self @unbare_repo diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index 813b15da..767d8419 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -707,12 +707,15 @@ class TestSubmodule(TestBase): def test_rename(self, rwdir): parent = git.Repo.init(os.path.join(rwdir, 'parent')) sm_name = 'mymodules/myname' - sm = parent.create_submodule(sm_name, 'submodules/intermediate/one', url=self._submodule_url()) + sm = parent.create_submodule(sm_name, sm_name, url=self._submodule_url()) parent.index.commit("Added submodule") assert sm._parent_commit is not None assert sm.rename(sm_name) is sm and sm.name == sm_name + new_path = 'renamed/myname' + assert sm.move(new_path).name == new_path + new_sm_name = "shortname" assert sm.rename(new_sm_name) is sm assert sm.exists() |