t / t7411-submodule-config.shon commit Merge branch 'ab/aix-needs-compat-regex' (5cea6ff)
   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
  34cat >super/expect <<EOF
  35Submodule name: 'a' for path 'a'
  36Submodule name: 'a' for path 'b'
  37Submodule name: 'submodule' for path 'submodule'
  38Submodule name: 'submodule' for path 'submodule'
  39EOF
  40
  41test_expect_success 'test parsing and lookup of submodule config by path' '
  42        (cd super &&
  43                test-submodule-config \
  44                        HEAD^ a \
  45                        HEAD b \
  46                        HEAD^ submodule \
  47                        HEAD submodule \
  48                                >actual &&
  49                test_cmp expect actual
  50        )
  51'
  52
  53test_expect_success 'test parsing and lookup of submodule config by name' '
  54        (cd super &&
  55                test-submodule-config --name \
  56                        HEAD^ a \
  57                        HEAD a \
  58                        HEAD^ submodule \
  59                        HEAD submodule \
  60                                >actual &&
  61                test_cmp expect actual
  62        )
  63'
  64
  65cat >super/expect_error <<EOF
  66Submodule name: 'a' for path 'b'
  67Submodule name: 'submodule' for path 'submodule'
  68EOF
  69
  70test_expect_success 'error in one submodule config lets continue' '
  71        (cd super &&
  72                cp .gitmodules .gitmodules.bak &&
  73                echo "  value = \"" >>.gitmodules &&
  74                git add .gitmodules &&
  75                mv .gitmodules.bak .gitmodules &&
  76                git commit -m "add error" &&
  77                test-submodule-config \
  78                        HEAD b \
  79                        HEAD submodule \
  80                                >actual &&
  81                test_cmp expect_error actual
  82        )
  83'
  84
  85test_expect_success 'error message contains blob reference' '
  86        (cd super &&
  87                sha1=$(git rev-parse HEAD) &&
  88                test-submodule-config \
  89                        HEAD b \
  90                        HEAD submodule \
  91                                2>actual_err &&
  92                test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_err >/dev/null
  93        )
  94'
  95
  96test_expect_success 'using different treeishs works' '
  97        (
  98                cd super &&
  99                git tag new_tag &&
 100                tree=$(git rev-parse HEAD^{tree}) &&
 101                commit=$(git rev-parse HEAD^{commit}) &&
 102                test-submodule-config $commit b >expect &&
 103                test-submodule-config $tree b >actual.1 &&
 104                test-submodule-config new_tag b >actual.2 &&
 105                test_cmp expect actual.1 &&
 106                test_cmp expect actual.2
 107        )
 108'
 109
 110cat >super/expect_url <<EOF
 111Submodule url: 'git@somewhere.else.net:a.git' for path 'b'
 112Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'
 113EOF
 114
 115cat >super/expect_local_path <<EOF
 116Submodule name: 'a' for path 'c'
 117Submodule name: 'submodule' for path 'submodule'
 118EOF
 119
 120test_expect_success 'reading of local configuration' '
 121        (cd super &&
 122                old_a=$(git config submodule.a.url) &&
 123                old_submodule=$(git config submodule.submodule.url) &&
 124                git config submodule.a.url git@somewhere.else.net:a.git &&
 125                git config submodule.submodule.url git@somewhere.else.net:submodule.git &&
 126                test-submodule-config --url \
 127                        "" b \
 128                        "" submodule \
 129                                >actual &&
 130                test_cmp expect_url actual &&
 131                git config submodule.a.path c &&
 132                test-submodule-config \
 133                        "" c \
 134                        "" submodule \
 135                                >actual &&
 136                test_cmp expect_local_path actual &&
 137                git config submodule.a.url "$old_a" &&
 138                git config submodule.submodule.url "$old_submodule" &&
 139                git config --unset submodule.a.path c
 140        )
 141'
 142
 143cat >super/expect_url <<EOF
 144Submodule url: '../submodule' for path 'b'
 145Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'
 146EOF
 147
 148test_expect_success 'reading of local configuration for uninitialized submodules' '
 149        (
 150                cd super &&
 151                git submodule deinit -f b &&
 152                old_submodule=$(git config submodule.submodule.url) &&
 153                git config submodule.submodule.url git@somewhere.else.net:submodule.git &&
 154                test-submodule-config --url \
 155                        "" b \
 156                        "" submodule \
 157                                >actual &&
 158                test_cmp expect_url actual &&
 159                git config submodule.submodule.url "$old_submodule" &&
 160                git submodule init b
 161        )
 162'
 163
 164cat >super/expect_fetchrecurse_die.err <<EOF
 165fatal: bad submodule.submodule.fetchrecursesubmodules argument: blabla
 166EOF
 167
 168test_expect_success 'local error in fetchrecursesubmodule dies early' '
 169        (cd super &&
 170                git config submodule.submodule.fetchrecursesubmodules blabla &&
 171                test_must_fail test-submodule-config \
 172                        "" b \
 173                        "" submodule \
 174                                >actual.out 2>actual.err &&
 175                touch expect_fetchrecurse_die.out &&
 176                test_cmp expect_fetchrecurse_die.out actual.out  &&
 177                test_cmp expect_fetchrecurse_die.err actual.err  &&
 178                git config --unset submodule.submodule.fetchrecursesubmodules
 179        )
 180'
 181
 182test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
 183        (cd super &&
 184                git config -f .gitmodules \
 185                        submodule.submodule.fetchrecursesubmodules blabla &&
 186                git add .gitmodules &&
 187                git config --unset -f .gitmodules \
 188                        submodule.submodule.fetchrecursesubmodules &&
 189                git commit -m "add error in fetchrecursesubmodules" &&
 190                test-submodule-config \
 191                        HEAD b \
 192                        HEAD submodule \
 193                                >actual &&
 194                test_cmp expect_error actual  &&
 195                git reset --hard HEAD^
 196        )
 197'
 198
 199test_done