Skip to content

Commit f326a06

Browse files
committed
Merge branch 'jn/submodule-b-current' into maint
* jn/submodule-b-current: git submodule: Remove now obsolete tests before cloning a repo git submodule -b ... of current HEAD fails
2 parents d84f280 + 69e7236 commit f326a06

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

git-submodule.sh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,6 @@ module_clone()
9393
url=$2
9494
reference="$3"
9595

96-
# If there already is a directory at the submodule path,
97-
# expect it to be empty (since that is the default checkout
98-
# action) and try to remove it.
99-
# Note: if $path is a symlink to a directory the test will
100-
# succeed but the rmdir will fail. We might want to fix this.
101-
if test -d "$path"
102-
then
103-
rmdir "$path" 2>/dev/null ||
104-
die "Directory '$path' exists, but is neither empty nor a git repository"
105-
fi
106-
107-
test -e "$path" &&
108-
die "A file already exist at path '$path'"
109-
11096
if test -n "$reference"
11197
then
11298
git-clone "$reference" -n "$url" "$path"
@@ -241,7 +227,7 @@ cmd_add()
241227
# ash fails to wordsplit ${branch:+-b "$branch"...}
242228
case "$branch" in
243229
'') git checkout -f -q ;;
244-
?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
230+
?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
245231
esac
246232
) || die "Unable to checkout submodule '$path'"
247233
fi

t/t7400-submodule-basic.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,29 @@ test_expect_success 'add submodules without specifying an explicit path' '
421421
git commit -m "repo commit 1"
422422
) &&
423423
git clone --bare repo/ bare.git &&
424-
cd addtest &&
425-
git submodule add "$submodurl/repo" &&
426-
git config -f .gitmodules submodule.repo.path repo &&
427-
git submodule add "$submodurl/bare.git" &&
428-
git config -f .gitmodules submodule.bare.path bare
424+
(
425+
cd addtest &&
426+
git submodule add "$submodurl/repo" &&
427+
git config -f .gitmodules submodule.repo.path repo &&
428+
git submodule add "$submodurl/bare.git" &&
429+
git config -f .gitmodules submodule.bare.path bare
430+
)
431+
'
432+
433+
test_expect_success 'add should fail when path is used by a file' '
434+
(
435+
cd addtest &&
436+
touch file &&
437+
test_must_fail git submodule add "$submodurl/repo" file
438+
)
439+
'
440+
441+
test_expect_success 'add should fail when path is used by an existing directory' '
442+
(
443+
cd addtest &&
444+
mkdir empty-dir &&
445+
test_must_fail git submodule add "$submodurl/repo" empty-dir
446+
)
429447
'
430448

431449
test_done

0 commit comments

Comments
 (0)