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