X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=t%2Ft7400-submodule-basic.sh;h=4fe3a41f07f2f05865b219ff00afaa5786c679d5;hb=e9c34c233f2e838c334f6e8a807ebc6a988e9509;hp=627472972918352a026408ddaa4a50d3e21522b5;hpb=d44c782bbd6b0e806e056f9e8ff8cd8e426e67a3;p=git.git diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 627472972..4fe3a41f0 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -18,29 +18,45 @@ 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' ' + : > t && + git-add t && + git-commit -m "initial commit" && + git branch initial HEAD && 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 module.lib.url ./.subrepo + 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' ' @@ -52,42 +68,56 @@ 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.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 + 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" + elif 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 && - head=$(cd lib && git-rev-parse HEAD) && + git-submodule update && + head=$(cd lib && git rev-parse HEAD) && if test -z "$head" then echo "[OOPS] Failed to obtain submodule head" @@ -99,20 +129,20 @@ 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" ' 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" @@ -122,12 +152,16 @@ 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) && + 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 @@ -140,4 +174,26 @@ 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_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