From 26fc5866f6ed994f3b9d859a3255b10d04ee653d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 15 Jan 2015 18:05:48 +0100 Subject: Verified that it apparently is impossible to add empty submodules using git-python. This is the case with `git submodule add` as well. This makes sense as an empty git repository doesn't have a commit, which needs to be specified as SHA in the parent repositories tree entry for the respective submodule. When manually adding the empty submodule to the .gitmodules file, git-python will throw another error related to the inability to find the submodule in the index. Even if an iteration would be possible, git-python would now throw a BadName exception, which clearly indicates that the 'HEAD' revision is invalid (as it doesn't point to any commit). Fixes #152 Fixes #105 --- git/test/test_submodule.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index 75edf6e5..2be0e795 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -1,19 +1,21 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php +import shutil +import sys +import os + +import git from git.test.lib import ( TestBase, with_rw_repo ) +from gitdb.test.lib import with_rw_directory from git.exc import InvalidGitRepositoryError from git.objects.submodule.base import Submodule from git.objects.submodule.root import RootModule, RootUpdateProgress from git.util import to_native_path_linux, join_path_native from git.compat import string_types -import shutil -import git -import sys -import os from nose import SkipTest @@ -597,3 +599,17 @@ class TestSubmodule(TestBase): self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail', os.path.expanduser('~')) self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail-too', rwrepo.working_tree_dir + os.path.sep) + + @with_rw_directory + def test_add_empty_repo(self, rwdir): + parent_dir = os.path.join(rwdir, 'parent') + os.mkdir(parent_dir) + empty_repo_dir = os.path.join(rwdir, 'empty-repo') + + parent = git.Repo.init(parent_dir) + git.Repo.init(empty_repo_dir) + + for checkout_mode in range(2): + self.failUnlessRaises(ValueError, parent.create_submodule, 'empty', 'empty', + url=empty_repo_dir, no_checkout=checkout_mode) + # end for each checkout mode -- cgit v1.2.1