t / t7411-submodule-config.shon commit t7411: check configuration parsing errors (5ea5095)
   1#!/bin/sh
   2#
   3# Copyright (c) 2014 Heiko Voigt
   4#
   5
   6test_description='Test submodules config cache infrastructure
   7
   8This test verifies that parsing .gitmodules configurations directly
   9from the database and from the worktree works.
  10'
  11
  12TEST_NO_CREATE_REPO=1
  13. ./test-lib.sh
  14
  15test_expect_success 'submodule config cache setup' '
  16        mkdir submodule &&
  17        (cd submodule &&
  18                git init &&
  19                echo a >a &&
  20                git add . &&
  21                git commit -ma
  22        ) &&
  23        mkdir super &&
  24        (cd super &&
  25                git init &&
  26                git submodule add ../submodule &&
  27                git submodule add ../submodule a &&
  28                git commit -m "add as submodule and as a" &&
  29                git mv a b &&
  30                git commit -m "move a to b"
  31        )
  32'
  33
  34test_expect_success 'configuration parsing with error' '
  35        test_when_finished "rm -rf repo" &&
  36        test_create_repo repo &&
  37        cat >repo/.gitmodules <<-\EOF &&
  38        [submodule "s"]
  39                path
  40                ignore
  41        EOF
  42        (
  43                cd repo &&
  44                test_must_fail test-submodule-config "" s 2>actual &&
  45                test_i18ngrep "bad config" actual
  46        )
  47'
  48
  49cat >super/expect <<EOF
  50Submodule name: 'a' for path 'a'
  51Submodule name: 'a' for path 'b'
  52Submodule name: 'submodule' for path 'submodule'
  53Submodule name: 'submodule' for path 'submodule'
  54EOF
  55
  56test_expect_success 'test parsing and lookup of submodule config by path' '
  57        (cd super &&
  58                test-submodule-config \
  59                        HEAD^ a \
  60                        HEAD b \
  61                        HEAD^ submodule \
  62                        HEAD submodule \
  63                                >actual &&
  64                test_cmp expect actual
  65        )
  66'
  67
  68test_expect_success 'test parsing and lookup of submodule config by name' '
  69        (cd super &&
  70                test-submodule-config --name \
  71                        HEAD^ a \
  72                        HEAD a \
  73                        HEAD^ submodule \
  74                        HEAD submodule \
  75                                >actual &&
  76                test_cmp expect actual
  77        )
  78'
  79
  80cat >super/expect_error <<EOF
  81Submodule name: 'a' for path 'b'
  82Submodule name: 'submodule' for path 'submodule'
  83EOF
  84
  85test_expect_success 'error in one submodule config lets continue' '
  86        (cd super &&
  87                cp .gitmodules .gitmodules.bak &&
  88                echo "  value = \"" >>.gitmodules &&
  89                git add .gitmodules &&
  90                mv .gitmodules.bak .gitmodules &&
  91                git commit -m "add error" &&
  92                test-submodule-config \
  93                        HEAD b \
  94                        HEAD submodule \
  95                                >actual &&
  96                test_cmp expect_error actual
  97        )
  98'
  99
 100test_expect_success 'error message contains blob reference' '
 101        (cd super &&
 102                sha1=$(git rev-parse HEAD) &&
 103                test-submodule-config \
 104                        HEAD b \
 105                        HEAD submodule \
 106                                2>actual_err &&
 107                test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_err >/dev/null
 108        )
 109'
 110
 111test_expect_success 'using different treeishs works' '
 112        (
 113                cd super &&
 114                git tag new_tag &&
 115                tree=$(git rev-parse HEAD^{tree}) &&
 116                commit=$(git rev-parse HEAD^{commit}) &&
 117                test-submodule-config $commit b >expect &&
 118                test-submodule-config $tree b >actual.1 &&
 119                test-submodule-config new_tag b >actual.2 &&
 120                test_cmp expect actual.1 &&
 121                test_cmp expect actual.2
 122        )
 123'
 124
 125cat >super/expect_url <<EOF
 126Submodule url: 'git@somewhere.else.net:a.git' for path 'b'
 127Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'
 128EOF
 129
 130cat >super/expect_local_path <<EOF
 131Submodule name: 'a' for path 'c'
 132Submodule name: 'submodule' for path 'submodule'
 133EOF
 134
 135test_expect_success 'reading of local configuration' '
 136        (cd super &&
 137                old_a=$(git config submodule.a.url) &&
 138                old_submodule=$(git config submodule.submodule.url) &&
 139                git config submodule.a.url git@somewhere.else.net:a.git &&
 140                git config submodule.submodule.url git@somewhere.else.net:submodule.git &&
 141                test-submodule-config --url \
 142                        "" b \
 143                        "" submodule \
 144                                >actual &&
 145                test_cmp expect_url actual &&
 146                git config submodule.a.path c &&
 147                test-submodule-config \
 148                        "" c \
 149                        "" submodule \
 150                                >actual &&
 151                test_cmp expect_local_path actual &&
 152                git config submodule.a.url "$old_a" &&
 153                git config submodule.submodule.url "$old_submodule" &&
 154                git config --unset submodule.a.path c
 155        )
 156'
 157
 158cat >super/expect_url <<EOF
 159Submodule url: '../submodule' for path 'b'
 160Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'
 161EOF
 162
 163test_expect_success 'reading of local configuration for uninitialized submodules' '
 164        (
 165                cd super &&
 166                git submodule deinit -f b &&
 167                old_submodule=$(git config submodule.submodule.url) &&
 168                git config submodule.submodule.url git@somewhere.else.net:submodule.git &&
 169                test-submodule-config --url \
 170                        "" b \
 171                        "" submodule \
 172                                >actual &&
 173                test_cmp expect_url actual &&
 174                git config submodule.submodule.url "$old_submodule" &&
 175                git submodule init b
 176        )
 177'
 178
 179cat >super/expect_fetchrecurse_die.err <<EOF
 180fatal: bad submodule.submodule.fetchrecursesubmodules argument: blabla
 181EOF
 182
 183test_expect_success 'local error in fetchrecursesubmodule dies early' '
 184        (cd super &&
 185                git config submodule.submodule.fetchrecursesubmodules blabla &&
 186                test_must_fail test-submodule-config \
 187                        "" b \
 188                        "" submodule \
 189                                >actual.out 2>actual.err &&
 190                touch expect_fetchrecurse_die.out &&
 191                test_cmp expect_fetchrecurse_die.out actual.out  &&
 192                test_cmp expect_fetchrecurse_die.err actual.err  &&
 193                git config --unset submodule.submodule.fetchrecursesubmodules
 194        )
 195'
 196
 197test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
 198        (cd super &&
 199                git config -f .gitmodules \
 200                        submodule.submodule.fetchrecursesubmodules blabla &&
 201                git add .gitmodules &&
 202                git config --unset -f .gitmodules \
 203                        submodule.submodule.fetchrecursesubmodules &&
 204                git commit -m "add error in fetchrecursesubmodules" &&
 205                test-submodule-config \
 206                        HEAD b \
 207                        HEAD submodule \
 208                                >actual &&
 209                test_cmp expect_error actual  &&
 210                git reset --hard HEAD^
 211        )
 212'
 213
 214test_done