From 88961ef2589433044365213fab98de081a1ce70f Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 2 Jun 2007 03:27:42 +0200 Subject: Add basic test-script for git-submodule This test tries to verify basic sanity of git-submodule, i.e. that it is able to clone and update a submodule repository, that its status output is sane, and that it barfs when the submodule path is occupied during init. Signed-off-by: Lars Hjemli Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 143 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100755 t/t7400-submodule-basic.sh (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh new file mode 100755 index 0000000000..6274729729 --- /dev/null +++ b/t/t7400-submodule-basic.sh @@ -0,0 +1,143 @@ +#!/bin/sh +# +# Copyright (c) 2007 Lars Hjemli +# + +test_description='Basic porcelain support for submodules + +This test tries to verify basic sanity of the init, update and status +subcommands of git-submodule. +' + +. ./test-lib.sh + +# +# Test setup: +# -create a repository in directory lib +# -add a couple of files +# -add directory lib to 'superproject', this creates a DIRLINK entry +# -add a couple of regular files to enable testing of submodule filtering +# -mv lib subrepo +# -add an entry to .gitmodules for path 'lib' +# +test_expect_success 'Prepare submodule testing' ' + mkdir lib && + cd lib && + git-init && + echo a >a && + git-add a && + git-commit -m "submodule commit 1" && + git-tag -a -m "rev-1" rev-1 && + rev1=$(git-rev-parse HEAD) && + if test -z "$rev1" + then + echo "[OOPS] submodule git-rev-parse returned nothing" + false + fi && + cd .. && + echo a >a && + echo z >z && + git-add a lib z && + git-commit -m "super commit 1" && + mv lib .subrepo && + GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo +' + +test_expect_success 'status should only print one line' ' + lines=$(git-submodule status | wc -l) && + test $lines = 1 +' + +test_expect_success 'status should initially be "missing"' ' + git-submodule status | grep "^-$rev1" +' + +test_expect_success 'init should fail when path is used by a file' ' + echo "hello" >lib && + if git-submodule init + then + echo "[OOPS] init should have failed" + false + elif test -f lib && test "$(cat lib)" != "hello" + then + echo "[OOPS] init failed but lib file was molested" + false + else + rm lib + fi +' + +test_expect_success 'init should fail when path is used by a nonempty directory' ' + mkdir lib && + echo "hello" >lib/a && + if git-submodule init + then + echo "[OOPS] init should have failed" + false + elif test "$(cat lib/a)" != "hello" + then + echo "[OOPS] init failed but lib/a was molested" + false + else + rm lib/a + fi +' + +test_expect_success 'init should work when path is an empty dir' ' + rm -rf lib && + mkdir lib && + git-submodule init && + head=$(cd lib && git-rev-parse HEAD) && + if test -z "$head" + then + echo "[OOPS] Failed to obtain submodule head" + false + elif test "$head" != "$rev1" + then + echo "[OOPS] Submodule head is $head but should have been $rev1" + false + fi +' + +test_expect_success 'status should be "up-to-date" after init' ' + git-submodule status | grep "^ $rev1" +' + +test_expect_success 'status should be "modified" after submodule commit' ' + cd lib && + echo b >b && + git-add b && + git-commit -m "submodule commit 2" && + rev2=$(git-rev-parse HEAD) && + cd .. && + if test -z "$rev2" + then + echo "[OOPS] submodule git-rev-parse returned nothing" + false + fi && + git-submodule status | grep "^+$rev2" +' + +test_expect_success 'the --cached sha1 should be rev1' ' + git-submodule --cached status | grep "^+$rev1" +' + +test_expect_success 'update should checkout rev1' ' + git-submodule update && + head=$(cd lib && git-rev-parse HEAD) && + if test -z "$head" + then + echo "[OOPS] submodule git-rev-parse returned nothing" + false + elif test "$head" != "$rev1" + then + echo "[OOPS] init did not checkout correct head" + false + fi +' + +test_expect_success 'status should be "up-to-date" after update' ' + git-submodule status | grep "^ $rev1" +' + +test_done -- cgit v1.2.3 From 211b7f19c7b046a6cadd36d54c549e4f335f0519 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Wed, 6 Jun 2007 11:13:02 +0200 Subject: git-submodule: clone during update, not during init This teaches 'git-submodule init' to register submodule paths and urls in .git/config instead of actually cloning them. The cloning is now handled as part of 'git-submodule update'. With this change it is possible to specify preferred/alternate urls for the submodules in .git/config before the submodules are cloned. Signed-off-by: Lars Hjemli Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 6274729729..3940433b8f 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -40,7 +40,7 @@ test_expect_success 'Prepare submodule testing' ' git-add a lib z && git-commit -m "super commit 1" && mv lib .subrepo && - GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo + GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git ' test_expect_success 'status should only print one line' ' @@ -52,41 +52,55 @@ test_expect_success 'status should initially be "missing"' ' git-submodule status | grep "^-$rev1" ' -test_expect_success 'init should fail when path is used by a file' ' +test_expect_success 'init should register submodule url in .git/config' ' + git-submodule init && + url=$(git-config submodule.lib.url) && + if test "$url" != "git://example.com/lib.git" + then + echo "[OOPS] init succeeded but submodule url is wrong" + false + elif ! git-config submodule.lib.url ./.subrepo + then + echo "[OOPS] init succeeded but update of url failed" + false + fi +' + +test_expect_success 'update should fail when path is used by a file' ' echo "hello" >lib && - if git-submodule init + if git-submodule update then - echo "[OOPS] init should have failed" + echo "[OOPS] update should have failed" false elif test -f lib && test "$(cat lib)" != "hello" then - echo "[OOPS] init failed but lib file was molested" + echo "[OOPS] update failed but lib file was molested" false else rm lib fi ' -test_expect_success 'init should fail when path is used by a nonempty directory' ' +test_expect_success 'update should fail when path is used by a nonempty directory' ' mkdir lib && echo "hello" >lib/a && - if git-submodule init + if git-submodule update then - echo "[OOPS] init should have failed" + echo "[OOPS] update should have failed" false elif test "$(cat lib/a)" != "hello" then - echo "[OOPS] init failed but lib/a was molested" + echo "[OOPS] update failed but lib/a was molested" false else rm lib/a fi ' -test_expect_success 'init should work when path is an empty dir' ' +test_expect_success 'update should work when path is an empty dir' ' rm -rf lib && mkdir lib && - git-submodule init && + git-submodule update && head=$(cd lib && git-rev-parse HEAD) && if test -z "$head" then @@ -99,7 +113,7 @@ test_expect_success 'init should work when path is an empty dir' ' fi ' -test_expect_success 'status should be "up-to-date" after init' ' +test_expect_success 'status should be "up-to-date" after update' ' git-submodule status | grep "^ $rev1" ' -- cgit v1.2.3 From b10ee7606e14265c6116639aafccb863b77043f5 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 11 Jun 2007 21:12:21 +0200 Subject: t7400: barf if git-submodule removes or replaces a file The test for an unmolested file wouldn't fail properly if the file had been removed or replaced by something other than a regular file. This fixes it. Signed-off-by: Lars Hjemli Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 3940433b8f..74fafceb71 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -72,7 +72,7 @@ test_expect_success 'update should fail when path is used by a file' ' then echo "[OOPS] update should have failed" false - elif test -f lib && test "$(cat lib)" != "hello" + elif test "$(cat lib)" != "hello" then echo "[OOPS] update failed but lib file was molested" false -- cgit v1.2.3 From d57dd255a696cb68c880110a990085c08343f618 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 11 Jun 2007 21:12:23 +0200 Subject: Rename sections from "module" to "submodule" in .gitmodules Rename [module] to [submodule], so that it would be more forward compatible with the proposed extension by harmonizing the section names used in .gitmodules and .git/config. Signed-off-by: Lars Hjemli Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 74fafceb71..9f2d4f9b38 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -40,7 +40,7 @@ test_expect_success 'Prepare submodule testing' ' git-add a lib z && git-commit -m "super commit 1" && mv lib .subrepo && - GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git + GIT_CONFIG=.gitmodules git-config submodule.lib.url git://example.com/lib.git ' test_expect_success 'status should only print one line' ' -- cgit v1.2.3 From 941987a554812b982094e09c5c817f18be953365 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 11 Jun 2007 21:12:24 +0200 Subject: git-submodule: give submodules proper names This changes the way git-submodule uses .gitmodules: Subsections no longer specify the submodule path, they now specify the submodule name. The submodule path is found under the new key "submodule..path", which is a required key. With this change a submodule can be moved between different 'checkout paths' without upsetting git-submodule. Signed-off-by: Lars Hjemli Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 9f2d4f9b38..7a9b505b13 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -18,7 +18,7 @@ subcommands of git-submodule. # -add directory lib to 'superproject', this creates a DIRLINK entry # -add a couple of regular files to enable testing of submodule filtering # -mv lib subrepo -# -add an entry to .gitmodules for path 'lib' +# -add an entry to .gitmodules for submodule 'example' # test_expect_success 'Prepare submodule testing' ' mkdir lib && @@ -40,7 +40,19 @@ test_expect_success 'Prepare submodule testing' ' git-add a lib z && git-commit -m "super commit 1" && mv lib .subrepo && - GIT_CONFIG=.gitmodules git-config submodule.lib.url git://example.com/lib.git + GIT_CONFIG=.gitmodules git-config submodule.example.url git://example.com/lib.git +' + +test_expect_success 'status should fail for unmapped paths' ' + if git-submodule status + then + echo "[OOPS] submodule status succeeded" + false + elif ! GIT_CONFIG=.gitmodules git-config submodule.example.path lib + then + echo "[OOPS] git-config failed to update .gitmodules" + false + fi ' test_expect_success 'status should only print one line' ' @@ -54,12 +66,12 @@ test_expect_success 'status should initially be "missing"' ' test_expect_success 'init should register submodule url in .git/config' ' git-submodule init && - url=$(git-config submodule.lib.url) && + url=$(git-config submodule.example.url) && if test "$url" != "git://example.com/lib.git" then echo "[OOPS] init succeeded but submodule url is wrong" false - elif ! git-config submodule.lib.url ./.subrepo + elif ! git-config submodule.example.url ./.subrepo then echo "[OOPS] init succeeded but update of url failed" false -- cgit v1.2.3 From 5be60078c935ed08ee8eb5a32680bdfb6bb5bdf3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2007 22:52:14 -0700 Subject: Rewrite "git-frotz" to "git frotz" This uses the remove-dashes target to replace "git-frotz" to "git frotz". Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 7a9b505b13..5e91db64e9 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -23,24 +23,24 @@ subcommands of git-submodule. test_expect_success 'Prepare submodule testing' ' mkdir lib && cd lib && - git-init && + git init && echo a >a && - git-add a && + git add a && git-commit -m "submodule commit 1" && git-tag -a -m "rev-1" rev-1 && - rev1=$(git-rev-parse HEAD) && + rev1=$(git rev-parse HEAD) && if test -z "$rev1" then - echo "[OOPS] submodule git-rev-parse returned nothing" + echo "[OOPS] submodule git rev-parse returned nothing" false fi && cd .. && echo a >a && echo z >z && - git-add a lib z && + git add a lib z && git-commit -m "super commit 1" && mv lib .subrepo && - GIT_CONFIG=.gitmodules git-config submodule.example.url git://example.com/lib.git + GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/lib.git ' test_expect_success 'status should fail for unmapped paths' ' @@ -48,9 +48,9 @@ test_expect_success 'status should fail for unmapped paths' ' then echo "[OOPS] submodule status succeeded" false - elif ! GIT_CONFIG=.gitmodules git-config submodule.example.path lib + elif ! GIT_CONFIG=.gitmodules git config submodule.example.path lib then - echo "[OOPS] git-config failed to update .gitmodules" + echo "[OOPS] git config failed to update .gitmodules" false fi ' @@ -66,12 +66,12 @@ test_expect_success 'status should initially be "missing"' ' test_expect_success 'init should register submodule url in .git/config' ' git-submodule init && - url=$(git-config submodule.example.url) && + url=$(git config submodule.example.url) && if test "$url" != "git://example.com/lib.git" then echo "[OOPS] init succeeded but submodule url is wrong" false - elif ! git-config submodule.example.url ./.subrepo + elif ! git config submodule.example.url ./.subrepo then echo "[OOPS] init succeeded but update of url failed" false @@ -113,7 +113,7 @@ test_expect_success 'update should work when path is an empty dir' ' rm -rf lib && mkdir lib && git-submodule update && - head=$(cd lib && git-rev-parse HEAD) && + head=$(cd lib && git rev-parse HEAD) && if test -z "$head" then echo "[OOPS] Failed to obtain submodule head" @@ -132,13 +132,13 @@ test_expect_success 'status should be "up-to-date" after update' ' test_expect_success 'status should be "modified" after submodule commit' ' cd lib && echo b >b && - git-add b && + git add b && git-commit -m "submodule commit 2" && - rev2=$(git-rev-parse HEAD) && + rev2=$(git rev-parse HEAD) && cd .. && if test -z "$rev2" then - echo "[OOPS] submodule git-rev-parse returned nothing" + echo "[OOPS] submodule git rev-parse returned nothing" false fi && git-submodule status | grep "^+$rev2" @@ -150,10 +150,10 @@ test_expect_success 'the --cached sha1 should be rev1' ' test_expect_success 'update should checkout rev1' ' git-submodule update && - head=$(cd lib && git-rev-parse HEAD) && + head=$(cd lib && git rev-parse HEAD) && if test -z "$head" then - echo "[OOPS] submodule git-rev-parse returned nothing" + echo "[OOPS] submodule git rev-parse returned nothing" false elif test "$head" != "$rev1" then -- cgit v1.2.3 From 0cf7375542504e3762753cdc4cff3bb5c8fc628e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 17 Jul 2007 20:28:28 +0200 Subject: unpack-trees.c: assume submodules are clean during check-out In particular, when moving back to a commit without a given submodule and then moving back forward to a commit with the given submodule, we shouldn't complain that updating would lose untracked file in the submodule, because git currently does not checkout subprojects during superproject check-out. Signed-off-by: Sven Verdoolaege Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 5e91db64e9..e8ce7cdb83 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -21,6 +21,10 @@ subcommands of git-submodule. # -add an entry to .gitmodules for submodule 'example' # test_expect_success 'Prepare submodule testing' ' + : > t && + git-add t && + git-commit -m "initial commit" && + git branch initial HEAD && mkdir lib && cd lib && git init && @@ -166,4 +170,9 @@ test_expect_success 'status should be "up-to-date" after update' ' git-submodule status | grep "^ $rev1" ' +test_expect_success 'checkout superproject with subproject already present' ' + git-checkout initial && + git-checkout master +' + test_done -- cgit v1.2.3 From e06c5a6c7bdaa8c96b72e29f7fb49a331f1e0cc2 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 15 Aug 2007 19:22:09 +0200 Subject: git-apply: apply submodule changes Apply "Subproject commit HEX" changes produced by git-diff. As usual in the current git, only the superproject itself is actually modified (possibly creating empty directories for new submodules). Any checked-out submodule is left untouched and is not required to be up-to-date. With clean-ups from Junio C Hamano. Signed-off-by: Sven Verdoolaege Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index e8ce7cdb83..9d142ed649 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -175,4 +175,21 @@ test_expect_success 'checkout superproject with subproject already present' ' git-checkout master ' +test_expect_success 'apply submodule diff' ' + git branch second && + ( + cd lib && + echo s >s && + git add s && + git commit -m "change subproject" + ) && + git update-index --add lib && + git-commit -m "change lib" && + git-format-patch -1 --stdout >P.diff && + git checkout second && + git apply --index P.diff && + D=$(git diff --cached master) && + test -z "$D" +' + test_done -- cgit v1.2.3 From 5701115aa7cfe7edd57c2483085456a37e27a5ba Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 8 Sep 2007 12:30:22 +0200 Subject: git-diff: don't squelch the new SHA1 in submodule diffs The code to squelch empty diffs introduced by commit fb13227e089f22dc31a3b1624559153821056848 would inadvertently populate filespec "two" of a submodule change using the uninitialized (null) SHA1, thereby replacing the submodule SHA1 by 0{40} in the output. This change teaches diffcore_skip_stat_unmatch to handle submodule changes correctly. Signed-off-by: Sven Verdoolaege Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 9d142ed649..4fe3a41f07 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -152,6 +152,10 @@ test_expect_success 'the --cached sha1 should be rev1' ' git-submodule --cached status | grep "^+$rev1" ' +test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' + git-diff | grep "^+Subproject commit $rev2" +' + test_expect_success 'update should checkout rev1' ' git-submodule update && head=$(cd lib && git rev-parse HEAD) && -- cgit v1.2.3 From a2d93aea25e33468622fbd6d9a6e02f8dd8b3c58 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 15 Jan 2008 03:13:55 -0800 Subject: git-submodule: add test for the subcommand parser fix This modifies the existing t7400 test to use 'init' as the pathname that a submodule is bound to. Without the earlier subcommand parser fix, this fails. Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 4fe3a41f07..2ef85a869d 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -13,11 +13,11 @@ subcommands of git-submodule. # # Test setup: -# -create a repository in directory lib +# -create a repository in directory init # -add a couple of files -# -add directory lib to 'superproject', this creates a DIRLINK entry +# -add directory init to 'superproject', this creates a DIRLINK entry # -add a couple of regular files to enable testing of submodule filtering -# -mv lib subrepo +# -mv init subrepo # -add an entry to .gitmodules for submodule 'example' # test_expect_success 'Prepare submodule testing' ' @@ -25,8 +25,8 @@ test_expect_success 'Prepare submodule testing' ' git-add t && git-commit -m "initial commit" && git branch initial HEAD && - mkdir lib && - cd lib && + mkdir init && + cd init && git init && echo a >a && git add a && @@ -41,10 +41,10 @@ test_expect_success 'Prepare submodule testing' ' cd .. && echo a >a && echo z >z && - git add a lib z && + git add a init z && git-commit -m "super commit 1" && - mv lib .subrepo && - GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/lib.git + mv init .subrepo && + GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git ' test_expect_success 'status should fail for unmapped paths' ' @@ -52,7 +52,7 @@ test_expect_success 'status should fail for unmapped paths' ' then echo "[OOPS] submodule status succeeded" false - elif ! GIT_CONFIG=.gitmodules git config submodule.example.path lib + elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init then echo "[OOPS] git config failed to update .gitmodules" false @@ -71,7 +71,7 @@ test_expect_success 'status should initially be "missing"' ' test_expect_success 'init should register submodule url in .git/config' ' git-submodule init && url=$(git config submodule.example.url) && - if test "$url" != "git://example.com/lib.git" + if test "$url" != "git://example.com/init.git" then echo "[OOPS] init succeeded but submodule url is wrong" false @@ -83,41 +83,41 @@ test_expect_success 'init should register submodule url in .git/config' ' ' test_expect_success 'update should fail when path is used by a file' ' - echo "hello" >lib && + echo "hello" >init && if git-submodule update then echo "[OOPS] update should have failed" false - elif test "$(cat lib)" != "hello" + elif test "$(cat init)" != "hello" then - echo "[OOPS] update failed but lib file was molested" + echo "[OOPS] update failed but init file was molested" false else - rm lib + rm init fi ' test_expect_success 'update should fail when path is used by a nonempty directory' ' - mkdir lib && - echo "hello" >lib/a && + mkdir init && + echo "hello" >init/a && if git-submodule update then echo "[OOPS] update should have failed" false - elif test "$(cat lib/a)" != "hello" + elif test "$(cat init/a)" != "hello" then - echo "[OOPS] update failed but lib/a was molested" + echo "[OOPS] update failed but init/a was molested" false else - rm lib/a + rm init/a fi ' test_expect_success 'update should work when path is an empty dir' ' - rm -rf lib && - mkdir lib && + rm -rf init && + mkdir init && git-submodule update && - head=$(cd lib && git rev-parse HEAD) && + head=$(cd init && git rev-parse HEAD) && if test -z "$head" then echo "[OOPS] Failed to obtain submodule head" @@ -134,7 +134,7 @@ test_expect_success 'status should be "up-to-date" after update' ' ' test_expect_success 'status should be "modified" after submodule commit' ' - cd lib && + cd init && echo b >b && git add b && git-commit -m "submodule commit 2" && @@ -157,8 +157,8 @@ test_expect_success 'git diff should report the SHA1 of the new submodule commit ' test_expect_success 'update should checkout rev1' ' - git-submodule update && - head=$(cd lib && git rev-parse HEAD) && + git-submodule update init && + head=$(cd init && git rev-parse HEAD) && if test -z "$head" then echo "[OOPS] submodule git rev-parse returned nothing" @@ -182,13 +182,13 @@ test_expect_success 'checkout superproject with subproject already present' ' test_expect_success 'apply submodule diff' ' git branch second && ( - cd lib && + cd init && echo s >s && git add s && git commit -m "change subproject" ) && - git update-index --add lib && - git-commit -m "change lib" && + git update-index --add init && + git-commit -m "change init" && git-format-patch -1 --stdout >P.diff && git checkout second && git apply --index P.diff && -- cgit v1.2.3 From be4d2c83b68a96285cc05036add4d64d324e52d9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 16 May 2008 11:23:03 +0100 Subject: submodule update: add convenience option --init When a submodule is not initialized and you do not want to change the defaults from .gitmodules anyway, you can now say $ git submodule update --init When "update" is called without --init on an uninitialized submodule, a hint to use --init is printed. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2ef85a869d..6c7b902482 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -196,4 +196,17 @@ test_expect_success 'apply submodule diff' ' test -z "$D" ' +test_expect_success 'update --init' ' + + mv init init2 && + git config -f .gitmodules submodule.example.url "$(pwd)/init2" && + git config --remove-section submodule.example + git submodule update init > update.out && + grep "not initialized" update.out && + test ! -d init/.git && + git submodule update --init init && + test -d init/.git + +' + test_done -- cgit v1.2.3 From d492b31cafe9aa5ce001b1d48815f4c0bb40d01a Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sat, 12 Jul 2008 17:47:52 +0200 Subject: t/: Use "test_must_fail git" instead of "! git" This patch changes every occurrence of "! git" -- with the meaning that a git call has to gracefully fail -- into "test_must_fail git". This is useful to - make sure the test does not fail because of a signal, e.g. SIGSEGV, and - advertise the use of "test_must_fail" for new tests. Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 6c7b902482..cbc0c34ce2 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -75,7 +75,7 @@ test_expect_success 'init should register submodule url in .git/config' ' then echo "[OOPS] init succeeded but submodule url is wrong" false - elif ! git config submodule.example.url ./.subrepo + elif test_must_fail git config submodule.example.url ./.subrepo then echo "[OOPS] init succeeded but update of url failed" false -- cgit v1.2.3 From 47a528ad24185133867ebb5bb7692db2cb8bef39 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Wed, 3 Sep 2008 17:59:33 +0900 Subject: tests: use "git xyzzy" form (t7200 - t9001) Converts tests between t7201-t9001. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index cbc0c34ce2..be73f7b60a 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -6,7 +6,7 @@ test_description='Basic porcelain support for submodules This test tries to verify basic sanity of the init, update and status -subcommands of git-submodule. +subcommands of git submodule. ' . ./test-lib.sh @@ -22,16 +22,16 @@ subcommands of git-submodule. # test_expect_success 'Prepare submodule testing' ' : > t && - git-add t && - git-commit -m "initial commit" && + git add t && + git commit -m "initial commit" && git branch initial HEAD && mkdir init && cd init && git init && echo a >a && git add a && - git-commit -m "submodule commit 1" && - git-tag -a -m "rev-1" rev-1 && + git commit -m "submodule commit 1" && + git tag -a -m "rev-1" rev-1 && rev1=$(git rev-parse HEAD) && if test -z "$rev1" then @@ -42,13 +42,13 @@ test_expect_success 'Prepare submodule testing' ' echo a >a && echo z >z && git add a init z && - git-commit -m "super commit 1" && + git commit -m "super commit 1" && mv init .subrepo && GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git ' test_expect_success 'status should fail for unmapped paths' ' - if git-submodule status + if git submodule status then echo "[OOPS] submodule status succeeded" false @@ -60,16 +60,16 @@ test_expect_success 'status should fail for unmapped paths' ' ' test_expect_success 'status should only print one line' ' - lines=$(git-submodule status | wc -l) && + lines=$(git submodule status | wc -l) && test $lines = 1 ' test_expect_success 'status should initially be "missing"' ' - git-submodule status | grep "^-$rev1" + git submodule status | grep "^-$rev1" ' test_expect_success 'init should register submodule url in .git/config' ' - git-submodule init && + git submodule init && url=$(git config submodule.example.url) && if test "$url" != "git://example.com/init.git" then @@ -84,7 +84,7 @@ test_expect_success 'init should register submodule url in .git/config' ' test_expect_success 'update should fail when path is used by a file' ' echo "hello" >init && - if git-submodule update + if git submodule update then echo "[OOPS] update should have failed" false @@ -100,7 +100,7 @@ test_expect_success 'update should fail when path is used by a file' ' test_expect_success 'update should fail when path is used by a nonempty directory' ' mkdir init && echo "hello" >init/a && - if git-submodule update + if git submodule update then echo "[OOPS] update should have failed" false @@ -116,7 +116,7 @@ test_expect_success 'update should fail when path is used by a nonempty director test_expect_success 'update should work when path is an empty dir' ' rm -rf init && mkdir init && - git-submodule update && + git submodule update && head=$(cd init && git rev-parse HEAD) && if test -z "$head" then @@ -130,14 +130,14 @@ test_expect_success 'update should work when path is an empty dir' ' ' test_expect_success 'status should be "up-to-date" after update' ' - git-submodule status | grep "^ $rev1" + git submodule status | grep "^ $rev1" ' test_expect_success 'status should be "modified" after submodule commit' ' cd init && echo b >b && git add b && - git-commit -m "submodule commit 2" && + git commit -m "submodule commit 2" && rev2=$(git rev-parse HEAD) && cd .. && if test -z "$rev2" @@ -145,19 +145,19 @@ test_expect_success 'status should be "modified" after submodule commit' ' echo "[OOPS] submodule git rev-parse returned nothing" false fi && - git-submodule status | grep "^+$rev2" + git submodule status | grep "^+$rev2" ' test_expect_success 'the --cached sha1 should be rev1' ' - git-submodule --cached status | grep "^+$rev1" + git submodule --cached status | grep "^+$rev1" ' test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' - git-diff | grep "^+Subproject commit $rev2" + git diff | grep "^+Subproject commit $rev2" ' test_expect_success 'update should checkout rev1' ' - git-submodule update init && + git submodule update init && head=$(cd init && git rev-parse HEAD) && if test -z "$head" then @@ -171,12 +171,12 @@ test_expect_success 'update should checkout rev1' ' ' test_expect_success 'status should be "up-to-date" after update' ' - git-submodule status | grep "^ $rev1" + git submodule status | grep "^ $rev1" ' test_expect_success 'checkout superproject with subproject already present' ' - git-checkout initial && - git-checkout master + git checkout initial && + git checkout master ' test_expect_success 'apply submodule diff' ' @@ -188,8 +188,8 @@ test_expect_success 'apply submodule diff' ' git commit -m "change subproject" ) && git update-index --add init && - git-commit -m "change init" && - git-format-patch -1 --stdout >P.diff && + git commit -m "change init" && + git format-patch -1 --stdout >P.diff && git checkout second && git apply --index P.diff && D=$(git diff --cached master) && -- cgit v1.2.3 From 2ce53f9b77eb36c6d1286f55fba65f8dc66b2564 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 2 Jan 2009 19:08:40 +0100 Subject: git add: do not add files from a submodule It comes quite as a surprise to an unsuspecting Git user that calling "git add submodule/file" (which is a mistake, alright) _removes_ the submodule in the index, and adds the file. Instead, complain loudly. While at it, be nice when the user said "git add submodule/" which is most likely the consequence of tab-completion, and stage the submodule, instead of trying to add the contents of that directory. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index be73f7b60a..2ec7ac6a51 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -209,4 +209,29 @@ test_expect_success 'update --init' ' ' +test_expect_success 'do not add files from a submodule' ' + + git reset --hard && + test_must_fail git add init/a + +' + +test_expect_success 'gracefully add submodule with a trailing slash' ' + + git reset --hard && + git commit -m "commit subproject" init && + (cd init && + echo b > a) && + git add init/ && + git diff --exit-code --cached init && + commit=$(cd init && + git commit -m update a >/dev/null && + git rev-parse HEAD) && + git add init/ && + test_must_fail git diff --exit-code --cached init && + test $commit = $(git ls-files --stage | + sed -n "s/^160000 \([^ ]*\).*/\1/p") + +' + test_done -- cgit v1.2.3 From f3670a5749d704fe1edee4201f9b23adbf0bf967 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 7 Feb 2009 14:43:03 +0100 Subject: Let ls-files strip trailing slashes in submodules' paths Tab completion makes it easy to add a trailing slash to a submodule path. As it is completely clear what the user actually wanted to say, be nice and strip that slash at the end. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2ec7ac6a51..a74f24c0db 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -234,4 +234,10 @@ test_expect_success 'gracefully add submodule with a trailing slash' ' ' +test_expect_success 'ls-files gracefully handles trailing slash' ' + + test "init" = "$(git ls-files init/)" + +' + test_done -- cgit v1.2.3 From 496917b721adae11e596cd44b13cb8a49c388de7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 7 Feb 2009 14:43:15 +0100 Subject: submodule: warn about non-submodules Earlier, when you called git submodule some/bogus/path Git would silently ignore the path, without warning the user about the likely mistake. Now it does. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index a74f24c0db..b8cb2df667 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -240,4 +240,11 @@ test_expect_success 'ls-files gracefully handles trailing slash' ' ' +test_expect_success 'submodule warns' ' + + git submodule no-such-submodule 2> output.err && + grep "^error: .*no-such-submodule" output.err + +' + test_done -- cgit v1.2.3 From ac8463d2b4c0e88011c40985bc519c0e2e2f2278 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Tue, 3 Mar 2009 16:08:20 +0100 Subject: git submodule: Add test cases for git submodule add Add simple test cases for adding and initialising submodules. The init step is necessary in order to verify the added information. The second test exposes a known breakage due to './' in the path: git ls-files simplifies the path but git add does not, which leads to git init looking for different lines in .gitmodules than git add adds. The other tests add test cases for '//' and '..' in the path which currently fail for the same reason. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2ec7ac6a51..132d0b9963 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -47,6 +47,55 @@ test_expect_success 'Prepare submodule testing' ' GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git ' +test_expect_success 'Prepare submodule add testing' ' + submodurl=$(pwd) + ( + mkdir addtest && + cd addtest && + git init + ) +' + +test_expect_success 'submodule add' ' + ( + cd addtest && + git submodule add "$submodurl" submod && + git submodule init + ) +' + +test_expect_failure 'submodule add with ./ in path' ' + ( + cd addtest && + git submodule add "$submodurl" ././dotsubmod/./frotz/./ && + git submodule init + ) +' + +test_expect_failure 'submodule add with // in path' ' + ( + cd addtest && + git submodule add "$submodurl" slashslashsubmod///frotz// && + git submodule init + ) +' + +test_expect_failure 'submodule add with /.. in path' ' + ( + cd addtest && + git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && + git submodule init + ) +' + +test_expect_failure 'submodule add with ./, /.. and // in path' ' + ( + cd addtest && + git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && + git submodule init + ) +' + test_expect_success 'status should fail for unmapped paths' ' if git submodule status then -- cgit v1.2.3 From db75ada559dd4de99fedd1fc4f62a9273f032dd3 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Tue, 3 Mar 2009 16:08:21 +0100 Subject: git submodule: Fix adding of submodules at paths with ./, .. and // Make 'git submodule add' normalize the submodule path in the same way as 'git ls-files' does, so that 'git submodule init' looks up the information in .gitmodules with the same key under which 'git submodule add' stores it. This fixes 4 known breakages. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 132d0b9963..21c19a28cf 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -64,7 +64,7 @@ test_expect_success 'submodule add' ' ) ' -test_expect_failure 'submodule add with ./ in path' ' +test_expect_success 'submodule add with ./ in path' ' ( cd addtest && git submodule add "$submodurl" ././dotsubmod/./frotz/./ && @@ -72,7 +72,7 @@ test_expect_failure 'submodule add with ./ in path' ' ) ' -test_expect_failure 'submodule add with // in path' ' +test_expect_success 'submodule add with // in path' ' ( cd addtest && git submodule add "$submodurl" slashslashsubmod///frotz// && @@ -80,7 +80,7 @@ test_expect_failure 'submodule add with // in path' ' ) ' -test_expect_failure 'submodule add with /.. in path' ' +test_expect_success 'submodule add with /.. in path' ' ( cd addtest && git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && @@ -88,7 +88,7 @@ test_expect_failure 'submodule add with /.. in path' ' ) ' -test_expect_failure 'submodule add with ./, /.. and // in path' ' +test_expect_success 'submodule add with ./, /.. and // in path' ' ( cd addtest && git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && -- cgit v1.2.3 From ea10b60c910e4a23483f47f17becc5e58f07ebe9 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 18 Apr 2009 20:42:07 -0700 Subject: Work around ash "alternate value" expansion bug Ash (used as /bin/sh on many distros) has a shell expansion bug for the form ${var:+word word}. The result is a single argument "word word". Work around by using ${var:+word} ${var:+word} or equivalent. Signed-off-by: Ben Jackson Signed-off-by: Junio C Hamano --- t/t7400-submodule-basic.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't/t7400-submodule-basic.sh') diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index af690ec6c1..0f2ccc6cf0 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -64,6 +64,16 @@ test_expect_success 'submodule add' ' ) ' +test_expect_success 'submodule add --branch' ' + ( + cd addtest && + git submodule add -b initial "$submodurl" submod-branch && + git submodule init && + cd submod-branch && + git branch | grep initial + ) +' + test_expect_success 'submodule add with ./ in path' ' ( cd addtest && -- cgit v1.2.3