summaryrefslogtreecommitdiff
path: root/t/t7400-submodule-basic.sh
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-04-10 05:39:04 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-04-11 04:30:59 (GMT)
commita76c944bbe207953c9f0f23311702d2b8225d486 (patch)
tree616d7af6c46118cca0c7987138c18162fcc7870d /t/t7400-submodule-basic.sh
parentfe454b13156e639adaae4526d04fd5b74eb8c84c (diff)
downloadgit-a76c944bbe207953c9f0f23311702d2b8225d486.zip
git-a76c944bbe207953c9f0f23311702d2b8225d486.tar.gz
git-a76c944bbe207953c9f0f23311702d2b8225d486.tar.bz2
t7400: clarify 'submodule add' tests
A new reader may not realize what properties the $submodurl repository needs to have. One of the tests is checking that ‘submodule add -b foo’ creates a ‘foo’ branch. Put this test in context by checking that without -b, no ‘foo’ branch is created. While at it, make sure each added submodule is a reasonable repository, with clean index, no stray files, and so on. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t7400-submodule-basic.sh')
-rwxr-xr-xt/t7400-submodule-basic.sh103
1 files changed, 88 insertions, 15 deletions
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 1f468e5..433a7d4 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -49,63 +49,136 @@ test_expect_success 'setup - add an example entry to .gitmodules' '
git config submodule.example.url git://example.com/init.git
'
-test_expect_success 'Prepare submodule add testing' '
- submodurl=$(pwd)
+test_expect_success 'setup - repository to add submodules to' '
+ git init addtest
+'
+
+# The 'submodule add' tests need some repository to add as a submodule.
+# The trash directory is a good one as any.
+submodurl=$TRASH_DIRECTORY
+
+listbranches() {
+ git for-each-ref --format='%(refname)' 'refs/heads/*'
+}
+
+inspect() {
+ dir=$1 &&
+ dotdot="${2:-..}" &&
+
(
- mkdir addtest &&
- cd addtest &&
- git init
+ cd "$dir" &&
+ listbranches >"$dotdot/heads" &&
+ { git symbolic-ref HEAD || :; } >"$dotdot/head" &&
+ git update-index --refresh &&
+ git diff-files --exit-code &&
+ git clean -n -d -x >"$dotdot/untracked"
)
-'
+}
test_expect_success 'submodule add' '
+ echo "refs/heads/master" >expect &&
+ >empty &&
+
(
cd addtest &&
git submodule add "$submodurl" submod &&
git submodule init
- )
+ ) &&
+
+ rm -f heads head untracked &&
+ inspect addtest/submod ../.. &&
+ test_cmp expect heads &&
+ test_cmp expect head &&
+ test_cmp empty untracked
'
test_expect_success 'submodule add --branch' '
+ echo "refs/heads/initial" >expect-head &&
+ cat <<-\EOF >expect-heads &&
+ refs/heads/initial
+ refs/heads/master
+ EOF
+ >empty &&
+
(
cd addtest &&
git submodule add -b initial "$submodurl" submod-branch &&
- git submodule init &&
- cd submod-branch &&
- git branch | grep initial
- )
+ git submodule init
+ ) &&
+
+ rm -f heads head untracked &&
+ inspect addtest/submod-branch ../.. &&
+ test_cmp expect-heads heads &&
+ test_cmp expect-head head &&
+ test_cmp empty untracked
'
test_expect_success 'submodule add with ./ in path' '
+ echo "refs/heads/master" >expect &&
+ >empty &&
+
(
cd addtest &&
git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
git submodule init
- )
+ ) &&
+
+ rm -f heads head untracked &&
+ inspect addtest/dotsubmod/frotz ../../.. &&
+ test_cmp expect heads &&
+ test_cmp expect head &&
+ test_cmp empty untracked
'
test_expect_success 'submodule add with // in path' '
+ echo "refs/heads/master" >expect &&
+ >empty &&
+
(
cd addtest &&
git submodule add "$submodurl" slashslashsubmod///frotz// &&
git submodule init
- )
+ ) &&
+
+ rm -f heads head untracked &&
+ inspect addtest/slashslashsubmod/frotz ../../.. &&
+ test_cmp expect heads &&
+ test_cmp expect head &&
+ test_cmp empty untracked
'
test_expect_success 'submodule add with /.. in path' '
+ echo "refs/heads/master" >expect &&
+ >empty &&
+
(
cd addtest &&
git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
git submodule init
- )
+ ) &&
+
+ rm -f heads head untracked &&
+ inspect addtest/realsubmod ../.. &&
+ test_cmp expect heads &&
+ test_cmp expect head &&
+ test_cmp empty untracked
'
test_expect_success 'submodule add with ./, /.. and // in path' '
+ echo "refs/heads/master" >expect &&
+ >empty &&
+
(
cd addtest &&
git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
git submodule init
- )
+ ) &&
+
+ rm -f heads head untracked &&
+ inspect addtest/realsubmod2 ../.. &&
+ test_cmp expect heads &&
+ test_cmp expect head &&
+ test_cmp empty untracked
'
test_expect_success 'status should fail for unmapped paths' '