Skip to content

Commit 26fc586

Browse files
committed
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
1 parent 508807e commit 26fc586

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

git/test/test_submodule.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# This module is part of GitPython and is released under
22
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
3+
import shutil
4+
import sys
5+
import os
6+
7+
import git
38

49
from git.test.lib import (
510
TestBase,
611
with_rw_repo
712
)
13+
from gitdb.test.lib import with_rw_directory
814
from git.exc import InvalidGitRepositoryError
915
from git.objects.submodule.base import Submodule
1016
from git.objects.submodule.root import RootModule, RootUpdateProgress
1117
from git.util import to_native_path_linux, join_path_native
1218
from git.compat import string_types
13-
import shutil
14-
import git
15-
import sys
16-
import os
1719

1820
from nose import SkipTest
1921

@@ -597,3 +599,17 @@ def test_first_submodule(self, rwrepo):
597599
self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail', os.path.expanduser('~'))
598600
self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail-too',
599601
rwrepo.working_tree_dir + os.path.sep)
602+
603+
@with_rw_directory
604+
def test_add_empty_repo(self, rwdir):
605+
parent_dir = os.path.join(rwdir, 'parent')
606+
os.mkdir(parent_dir)
607+
empty_repo_dir = os.path.join(rwdir, 'empty-repo')
608+
609+
parent = git.Repo.init(parent_dir)
610+
git.Repo.init(empty_repo_dir)
611+
612+
for checkout_mode in range(2):
613+
self.failUnlessRaises(ValueError, parent.create_submodule, 'empty', 'empty',
614+
url=empty_repo_dir, no_checkout=checkout_mode)
615+
# end for each checkout mode

0 commit comments

Comments
 (0)