From f2b92c66bed6d1eea7b8aefe3405b0898fbb2019 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sat, 1 Oct 2016 22:50:07 -0400 Subject: BF: Allow to remove a submodule with a remote without refs --- git/objects/submodule/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index c6c6d699..90f796bd 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -836,7 +836,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): num_branches_with_new_commits += len(mod.git.cherry(rref)) != 0 # END for each remote ref # not a single remote branch contained all our commits - if num_branches_with_new_commits == len(rrefs): + if len(rrefs) and num_branches_with_new_commits == len(rrefs): raise InvalidGitRepositoryError( "Cannot delete module at %s as there are new commits" % mod.working_tree_dir) # END handle new commits -- cgit v1.2.1 From 31fd955dfcc8176fd65f92fa859374387d3e0095 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sun, 2 Oct 2016 10:13:22 -0400 Subject: BF: @with_rw_directory must return decorated call As it was - many tests were simply not accounted/run at all --- git/test/lib/helper.py | 2 ++ git/test/test_submodule.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index a85ac2fd..cf5efa9e 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -107,6 +107,8 @@ def with_rw_directory(func): gc.collect() if not keep: rmtree(path) + wrapper.__name__ = func.__name__ + return wrapper def with_rw_repo(working_tree_ref, bare=False): diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index bfa0379d..eae6ab9f 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -317,8 +317,8 @@ class TestSubmodule(TestBase): # forcibly delete the child repository prev_count = len(sm.children()) self.failUnlessRaises(ValueError, csm.remove, force=True) - # We removed sm, which removed all submodules. Howver, the instance we have - # still points to the commit prior to that, where it still existed + # We removed sm, which removed all submodules. However, the instance we + # have still points to the commit prior to that, where it still existed csm.set_parent_commit(csm.repo.commit(), check=False) assert not csm.exists() assert not csm.module_exists() @@ -801,6 +801,31 @@ class TestSubmodule(TestBase): assert os.path.isdir(sm_module_path) == dry_run # end for each dry-run mode + @with_rw_directory + def test_remove_norefs(self, rwdir): + parent = git.Repo.init(os.path.join(rwdir, 'parent')) + sm_name = 'mymodules/myname' + sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url()) + parent.index.commit("Added submodule") + + # Adding a remote without fetching so would have no references + sm.repo.create_remote('special', 'git@server-shouldnotmatter:repo.git') + assert sm.rename(sm_name) is sm and sm.name == sm_name + assert not sm.repo.is_dirty(index=True, working_tree=False, untracked_files=False) + + 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.repo.is_dirty(index=True, working_tree=False, untracked_files=False) + assert sm.exists() + + sm_mod = sm.module() + if os.path.isfile(os.path.join(sm_mod.working_tree_dir, '.git')) == sm._need_gitfile_submodules(parent.git): + assert sm_mod.git_dir.endswith(join_path_native('.git', 'modules', new_sm_name)) + # end + @with_rw_directory def test_rename(self, rwdir): parent = git.Repo.init(os.path.join(rwdir, 'parent')) -- cgit v1.2.1 From 2528d11844a856838c0519e86fe08adc3feb5df1 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sun, 2 Oct 2016 10:24:46 -0400 Subject: BF: log.info is a function, just pass msg, no .write! --- git/test/lib/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index cf5efa9e..2d21f5bf 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -94,8 +94,8 @@ def with_rw_directory(func): try: return func(self, path) except Exception: - log.info.write("Test %s.%s failed, output is at %r\n", - type(self).__name__, func.__name__, path) + log.info("Test %s.%s failed, output is at %r\n", + type(self).__name__, func.__name__, path) keep = True raise finally: -- cgit v1.2.1 From f284a4e7c8861381b0139b76af4d5f970edb7400 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sun, 2 Oct 2016 10:27:53 -0400 Subject: TST: finishing test for removing submodule with remotes without refs originally draft committed by mistake in 31fd955dfcc8176fd65f92fa859374387d3e0095 sorry --- git/test/test_submodule.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index eae6ab9f..6dcf1831 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -806,25 +806,18 @@ class TestSubmodule(TestBase): parent = git.Repo.init(os.path.join(rwdir, 'parent')) sm_name = 'mymodules/myname' sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url()) + assert sm.exists() + parent.index.commit("Added submodule") + assert sm.repo is parent # yoh was surprised since expected sm repo!! + # so created a new instance for submodule + smrepo = git.Repo(os.path.join(rwdir, 'parent', sm.path)) # Adding a remote without fetching so would have no references - sm.repo.create_remote('special', 'git@server-shouldnotmatter:repo.git') - assert sm.rename(sm_name) is sm and sm.name == sm_name - assert not sm.repo.is_dirty(index=True, working_tree=False, untracked_files=False) - - 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.repo.is_dirty(index=True, working_tree=False, untracked_files=False) - assert sm.exists() - - sm_mod = sm.module() - if os.path.isfile(os.path.join(sm_mod.working_tree_dir, '.git')) == sm._need_gitfile_submodules(parent.git): - assert sm_mod.git_dir.endswith(join_path_native('.git', 'modules', new_sm_name)) - # end + smrepo.create_remote('special', 'git@server-shouldnotmatter:repo.git') + # And we should be able to remove it just fine + sm.remove() + assert not sm.exists() @with_rw_directory def test_rename(self, rwdir): -- cgit v1.2.1