git submodule: Remove now obsolete tests before cloning a repo
authorJens Lehmann <Jens.Lehmann@web.de>
Sat, 4 Dec 2010 23:27:35 +0000 (00:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Dec 2010 00:42:07 +0000 (16:42 -0800)
Since 55892d23 "git clone" itself checks that the destination path is not
a file but an empty directory if it exists, so there is no need anymore
for module_clone() to check that too.

Two tests have been added to test the behavior of "git submodule add" when
path is a file or a directory (A subshell had to be added to the former
last test to stay in the right directory).

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-submodule.sh
t/t7400-submodule-basic.sh
index 09107467fe0b6e6713b527b822c8cd13b47a8e24..a84418f1aabc8416d98f9ad49fc8f459435b7e91 100755 (executable)
@@ -93,20 +93,6 @@ module_clone()
        url=$2
        reference="$3"
 
-       # If there already is a directory at the submodule path,
-       # expect it to be empty (since that is the default checkout
-       # action) and try to remove it.
-       # Note: if $path is a symlink to a directory the test will
-       # succeed but the rmdir will fail. We might want to fix this.
-       if test -d "$path"
-       then
-               rmdir "$path" 2>/dev/null ||
-               die "Directory '$path' exists, but is neither empty nor a git repository"
-       fi
-
-       test -e "$path" &&
-       die "A file already exist at path '$path'"
-
        if test -n "$reference"
        then
                git-clone "$reference" -n "$url" "$path"
index 782b0a3ece7724bf8df7cf4d405715a42ad21d44..2c49db9f6244225db7f82b574f21f05b58bfdc26 100755 (executable)
@@ -421,11 +421,29 @@ test_expect_success 'add submodules without specifying an explicit path' '
                git commit -m "repo commit 1"
        ) &&
        git clone --bare repo/ bare.git &&
-       cd addtest &&
-       git submodule add "$submodurl/repo" &&
-       git config -f .gitmodules submodule.repo.path repo &&
-       git submodule add "$submodurl/bare.git" &&
-       git config -f .gitmodules submodule.bare.path bare
+       (
+               cd addtest &&
+               git submodule add "$submodurl/repo" &&
+               git config -f .gitmodules submodule.repo.path repo &&
+               git submodule add "$submodurl/bare.git" &&
+               git config -f .gitmodules submodule.bare.path bare
+       )
+'
+
+test_expect_success 'add should fail when path is used by a file' '
+       (
+               cd addtest &&
+               touch file &&
+               test_must_fail  git submodule add "$submodurl/repo" file
+       )
+'
+
+test_expect_success 'add should fail when path is used by an existing directory' '
+       (
+               cd addtest &&
+               mkdir empty-dir &&
+               test_must_fail git submodule add "$submodurl/repo" empty-dir
+       )
 '
 
 test_done