t / t3007-ls-files-recurse-submodules.shon commit test-lib: make "-x" work with "--verbose-log" (f5ba2de)
   1#!/bin/sh
   2
   3test_description='Test ls-files recurse-submodules feature
   4
   5This test verifies the recurse-submodules feature correctly lists files from
   6submodules.
   7'
   8
   9. ./test-lib.sh
  10
  11test_expect_success 'setup directory structure and submodules' '
  12        echo a >a &&
  13        mkdir b &&
  14        echo b >b/b &&
  15        git add a b &&
  16        git commit -m "add a and b" &&
  17        git init submodule &&
  18        echo c >submodule/c &&
  19        git -C submodule add c &&
  20        git -C submodule commit -m "add c" &&
  21        git submodule add ./submodule &&
  22        git commit -m "added submodule"
  23'
  24
  25test_expect_success 'ls-files correctly outputs files in submodule' '
  26        cat >expect <<-\EOF &&
  27        .gitmodules
  28        a
  29        b/b
  30        submodule/c
  31        EOF
  32
  33        git ls-files --recurse-submodules >actual &&
  34        test_cmp expect actual
  35'
  36
  37test_expect_success 'ls-files correctly outputs files in submodule with -z' '
  38        lf_to_nul >expect <<-\EOF &&
  39        .gitmodules
  40        a
  41        b/b
  42        submodule/c
  43        EOF
  44
  45        git ls-files --recurse-submodules -z >actual &&
  46        test_cmp expect actual
  47'
  48
  49test_expect_success 'ls-files does not output files not added to a repo' '
  50        cat >expect <<-\EOF &&
  51        .gitmodules
  52        a
  53        b/b
  54        submodule/c
  55        EOF
  56
  57        echo a >not_added &&
  58        echo b >b/not_added &&
  59        echo c >submodule/not_added &&
  60        git ls-files --recurse-submodules >actual &&
  61        test_cmp expect actual
  62'
  63
  64test_expect_success 'ls-files recurses more than 1 level' '
  65        cat >expect <<-\EOF &&
  66        .gitmodules
  67        a
  68        b/b
  69        submodule/.gitmodules
  70        submodule/c
  71        submodule/subsub/d
  72        EOF
  73
  74        git init submodule/subsub &&
  75        echo d >submodule/subsub/d &&
  76        git -C submodule/subsub add d &&
  77        git -C submodule/subsub commit -m "add d" &&
  78        git -C submodule submodule add ./subsub &&
  79        git -C submodule commit -m "added subsub" &&
  80        git submodule absorbgitdirs &&
  81        git ls-files --recurse-submodules >actual &&
  82        test_cmp expect actual
  83'
  84
  85test_expect_success 'ls-files works with GIT_DIR' '
  86        cat >expect <<-\EOF &&
  87        .gitmodules
  88        c
  89        subsub/d
  90        EOF
  91
  92        git --git-dir=submodule/.git ls-files --recurse-submodules >actual &&
  93        test_cmp expect actual
  94'
  95
  96test_expect_success '--recurse-submodules and pathspecs setup' '
  97        echo e >submodule/subsub/e.txt &&
  98        git -C submodule/subsub add e.txt &&
  99        git -C submodule/subsub commit -m "adding e.txt" &&
 100        echo f >submodule/f.TXT &&
 101        echo g >submodule/g.txt &&
 102        git -C submodule add f.TXT g.txt &&
 103        git -C submodule commit -m "add f and g" &&
 104        echo h >h.txt &&
 105        mkdir sib &&
 106        echo sib >sib/file &&
 107        git add h.txt sib/file &&
 108        git commit -m "add h and sib/file" &&
 109        git init sub &&
 110        echo sub >sub/file &&
 111        git -C sub add file &&
 112        git -C sub commit -m "add file" &&
 113        git submodule add ./sub &&
 114        git commit -m "added sub" &&
 115
 116        cat >expect <<-\EOF &&
 117        .gitmodules
 118        a
 119        b/b
 120        h.txt
 121        sib/file
 122        sub/file
 123        submodule/.gitmodules
 124        submodule/c
 125        submodule/f.TXT
 126        submodule/g.txt
 127        submodule/subsub/d
 128        submodule/subsub/e.txt
 129        EOF
 130
 131        git ls-files --recurse-submodules >actual &&
 132        test_cmp expect actual &&
 133        cat actual &&
 134        git ls-files --recurse-submodules "*" >actual &&
 135        test_cmp expect actual
 136'
 137
 138test_expect_success 'inactive submodule' '
 139        test_when_finished "git config --bool submodule.submodule.active true" &&
 140        test_when_finished "git -C submodule config --bool submodule.subsub.active true" &&
 141        git config --bool submodule.submodule.active "false" &&
 142
 143        cat >expect <<-\EOF &&
 144        .gitmodules
 145        a
 146        b/b
 147        h.txt
 148        sib/file
 149        sub/file
 150        submodule
 151        EOF
 152
 153        git ls-files --recurse-submodules >actual &&
 154        test_cmp expect actual &&
 155
 156        git config --bool submodule.submodule.active "true" &&
 157        git -C submodule config --bool submodule.subsub.active "false" &&
 158
 159        cat >expect <<-\EOF &&
 160        .gitmodules
 161        a
 162        b/b
 163        h.txt
 164        sib/file
 165        sub/file
 166        submodule/.gitmodules
 167        submodule/c
 168        submodule/f.TXT
 169        submodule/g.txt
 170        submodule/subsub
 171        EOF
 172
 173        git ls-files --recurse-submodules >actual &&
 174        test_cmp expect actual
 175'
 176
 177test_expect_success '--recurse-submodules and pathspecs' '
 178        cat >expect <<-\EOF &&
 179        h.txt
 180        submodule/g.txt
 181        submodule/subsub/e.txt
 182        EOF
 183
 184        git ls-files --recurse-submodules "*.txt" >actual &&
 185        test_cmp expect actual
 186'
 187
 188test_expect_success '--recurse-submodules and pathspecs' '
 189        cat >expect <<-\EOF &&
 190        h.txt
 191        submodule/f.TXT
 192        submodule/g.txt
 193        submodule/subsub/e.txt
 194        EOF
 195
 196        git ls-files --recurse-submodules ":(icase)*.txt" >actual &&
 197        test_cmp expect actual
 198'
 199
 200test_expect_success '--recurse-submodules and pathspecs' '
 201        cat >expect <<-\EOF &&
 202        h.txt
 203        submodule/f.TXT
 204        submodule/g.txt
 205        EOF
 206
 207        git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual &&
 208        test_cmp expect actual
 209'
 210
 211test_expect_success '--recurse-submodules and pathspecs' '
 212        cat >expect <<-\EOF &&
 213        sub/file
 214        EOF
 215
 216        git ls-files --recurse-submodules "sub" >actual &&
 217        test_cmp expect actual &&
 218        git ls-files --recurse-submodules "sub/" >actual &&
 219        test_cmp expect actual &&
 220        git ls-files --recurse-submodules "sub/file" >actual &&
 221        test_cmp expect actual &&
 222        git ls-files --recurse-submodules "su*/file" >actual &&
 223        test_cmp expect actual &&
 224        git ls-files --recurse-submodules "su?/file" >actual &&
 225        test_cmp expect actual
 226'
 227
 228test_expect_success '--recurse-submodules and pathspecs' '
 229        cat >expect <<-\EOF &&
 230        sib/file
 231        sub/file
 232        EOF
 233
 234        git ls-files --recurse-submodules "s??/file" >actual &&
 235        test_cmp expect actual &&
 236        git ls-files --recurse-submodules "s???file" >actual &&
 237        test_cmp expect actual &&
 238        git ls-files --recurse-submodules "s*file" >actual &&
 239        test_cmp expect actual
 240'
 241
 242test_expect_success '--recurse-submodules and relative paths' '
 243        # From subdir
 244        cat >expect <<-\EOF &&
 245        b
 246        EOF
 247        git -C b ls-files --recurse-submodules >actual &&
 248        test_cmp expect actual &&
 249
 250        # Relative path to top
 251        cat >expect <<-\EOF &&
 252        ../.gitmodules
 253        ../a
 254        b
 255        ../h.txt
 256        ../sib/file
 257        ../sub/file
 258        ../submodule/.gitmodules
 259        ../submodule/c
 260        ../submodule/f.TXT
 261        ../submodule/g.txt
 262        ../submodule/subsub/d
 263        ../submodule/subsub/e.txt
 264        EOF
 265        git -C b ls-files --recurse-submodules -- .. >actual &&
 266        test_cmp expect actual &&
 267
 268        # Relative path to submodule
 269        cat >expect <<-\EOF &&
 270        ../submodule/.gitmodules
 271        ../submodule/c
 272        ../submodule/f.TXT
 273        ../submodule/g.txt
 274        ../submodule/subsub/d
 275        ../submodule/subsub/e.txt
 276        EOF
 277        git -C b ls-files --recurse-submodules -- ../submodule >actual &&
 278        test_cmp expect actual
 279'
 280
 281test_expect_success '--recurse-submodules does not support --error-unmatch' '
 282        test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual &&
 283        test_i18ngrep "does not support --error-unmatch" actual
 284'
 285
 286test_incompatible_with_recurse_submodules () {
 287        test_expect_success "--recurse-submodules and $1 are incompatible" "
 288                test_must_fail git ls-files --recurse-submodules $1 2>actual &&
 289                test_i18ngrep 'unsupported mode' actual
 290        "
 291}
 292
 293test_incompatible_with_recurse_submodules --deleted
 294test_incompatible_with_recurse_submodules --modified
 295test_incompatible_with_recurse_submodules --others
 296test_incompatible_with_recurse_submodules --stage
 297test_incompatible_with_recurse_submodules --killed
 298test_incompatible_with_recurse_submodules --unmerged
 299
 300test_done