#!/bin/sh # # Copyright (c) 2014 Heiko Voigt # test_description='Test submodules config cache infrastructure This test verifies that parsing .gitmodules configurations directly from the database and from the worktree works. ' TEST_NO_CREATE_REPO=1 . ./test-lib.sh test_expect_success 'submodule config cache setup' ' mkdir submodule && (cd submodule && git init && echo a >a && git add . && git commit -ma ) && mkdir super && (cd super && git init && git submodule add ../submodule && git submodule add ../submodule a && git commit -m "add as submodule and as a" && git mv a b && git commit -m "move a to b" ) ' test_expect_success 'configuration parsing with error' ' test_when_finished "rm -rf repo" && test_create_repo repo && cat >repo/.gitmodules <<-\EOF && [submodule "s"] path ignore EOF ( cd repo && test_must_fail test-tool submodule-config "" s 2>actual && test_i18ngrep "bad config" actual ) ' cat >super/expect <actual && test_cmp expect actual ) ' test_expect_success 'test parsing and lookup of submodule config by name' ' (cd super && test-tool submodule-config --name \ HEAD^ a \ HEAD a \ HEAD^ submodule \ HEAD submodule \ >actual && test_cmp expect actual ) ' cat >super/expect_error <>.gitmodules && git add .gitmodules && mv .gitmodules.bak .gitmodules && git commit -m "add error" && sha1=$(git rev-parse HEAD) && test-tool submodule-config \ HEAD b \ HEAD submodule \ >actual \ 2>actual_stderr && test_cmp expect_error actual && test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null ) ' test_expect_success 'using different treeishs works' ' ( cd super && git tag new_tag && tree=$(git rev-parse HEAD^{tree}) && commit=$(git rev-parse HEAD^{commit}) && test-tool submodule-config $commit b >expect && test-tool submodule-config $tree b >actual.1 && test-tool submodule-config new_tag b >actual.2 && test_cmp expect actual.1 && test_cmp expect actual.2 ) ' test_expect_success 'error in history in fetchrecursesubmodule lets continue' ' ORIG=$(git -C super rev-parse HEAD) && test_when_finished "git -C super reset --hard $ORIG" && (cd super && git config -f .gitmodules \ submodule.submodule.fetchrecursesubmodules blabla && git add .gitmodules && git config --unset -f .gitmodules \ submodule.submodule.fetchrecursesubmodules && git commit -m "add error in fetchrecursesubmodules" && test-tool submodule-config \ HEAD b \ HEAD submodule \ >actual && test_cmp expect_error actual ) ' test_done