t / t3007-ls-files-recurse-submodules.shon commit grep: enable recurse-submodules to work on <tree> objects (74ed437)
   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 ls-files --recurse-submodules >actual &&
  81        test_cmp expect actual
  82'
  83
  84test_expect_success '--recurse-submodules and pathspecs setup' '
  85        echo e >submodule/subsub/e.txt &&
  86        git -C submodule/subsub add e.txt &&
  87        git -C submodule/subsub commit -m "adding e.txt" &&
  88        echo f >submodule/f.TXT &&
  89        echo g >submodule/g.txt &&
  90        git -C submodule add f.TXT g.txt &&
  91        git -C submodule commit -m "add f and g" &&
  92        echo h >h.txt &&
  93        mkdir sib &&
  94        echo sib >sib/file &&
  95        git add h.txt sib/file &&
  96        git commit -m "add h and sib/file" &&
  97        git init sub &&
  98        echo sub >sub/file &&
  99        git -C sub add file &&
 100        git -C sub commit -m "add file" &&
 101        git submodule add ./sub &&
 102        git commit -m "added sub" &&
 103
 104        cat >expect <<-\EOF &&
 105        .gitmodules
 106        a
 107        b/b
 108        h.txt
 109        sib/file
 110        sub/file
 111        submodule/.gitmodules
 112        submodule/c
 113        submodule/f.TXT
 114        submodule/g.txt
 115        submodule/subsub/d
 116        submodule/subsub/e.txt
 117        EOF
 118
 119        git ls-files --recurse-submodules >actual &&
 120        test_cmp expect actual &&
 121        cat actual &&
 122        git ls-files --recurse-submodules "*" >actual &&
 123        test_cmp expect actual
 124'
 125
 126test_expect_success '--recurse-submodules and pathspecs' '
 127        cat >expect <<-\EOF &&
 128        h.txt
 129        submodule/g.txt
 130        submodule/subsub/e.txt
 131        EOF
 132
 133        git ls-files --recurse-submodules "*.txt" >actual &&
 134        test_cmp expect actual
 135'
 136
 137test_expect_success '--recurse-submodules and pathspecs' '
 138        cat >expect <<-\EOF &&
 139        h.txt
 140        submodule/f.TXT
 141        submodule/g.txt
 142        submodule/subsub/e.txt
 143        EOF
 144
 145        git ls-files --recurse-submodules ":(icase)*.txt" >actual &&
 146        test_cmp expect actual
 147'
 148
 149test_expect_success '--recurse-submodules and pathspecs' '
 150        cat >expect <<-\EOF &&
 151        h.txt
 152        submodule/f.TXT
 153        submodule/g.txt
 154        EOF
 155
 156        git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual &&
 157        test_cmp expect actual
 158'
 159
 160test_expect_success '--recurse-submodules and pathspecs' '
 161        cat >expect <<-\EOF &&
 162        sub/file
 163        EOF
 164
 165        git ls-files --recurse-submodules "sub" >actual &&
 166        test_cmp expect actual &&
 167        git ls-files --recurse-submodules "sub/" >actual &&
 168        test_cmp expect actual &&
 169        git ls-files --recurse-submodules "sub/file" >actual &&
 170        test_cmp expect actual &&
 171        git ls-files --recurse-submodules "su*/file" >actual &&
 172        test_cmp expect actual &&
 173        git ls-files --recurse-submodules "su?/file" >actual &&
 174        test_cmp expect actual
 175'
 176
 177test_expect_success '--recurse-submodules and pathspecs' '
 178        cat >expect <<-\EOF &&
 179        sib/file
 180        sub/file
 181        EOF
 182
 183        git ls-files --recurse-submodules "s??/file" >actual &&
 184        test_cmp expect actual &&
 185        git ls-files --recurse-submodules "s???file" >actual &&
 186        test_cmp expect actual &&
 187        git ls-files --recurse-submodules "s*file" >actual &&
 188        test_cmp expect actual
 189'
 190
 191test_expect_success '--recurse-submodules does not support --error-unmatch' '
 192        test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual &&
 193        test_i18ngrep "does not support --error-unmatch" actual
 194'
 195
 196test_incompatible_with_recurse_submodules () {
 197        test_expect_success "--recurse-submodules and $1 are incompatible" "
 198                test_must_fail git ls-files --recurse-submodules $1 2>actual &&
 199                test_i18ngrep 'unsupported mode' actual
 200        "
 201}
 202
 203test_incompatible_with_recurse_submodules --deleted
 204test_incompatible_with_recurse_submodules --modified
 205test_incompatible_with_recurse_submodules --others
 206test_incompatible_with_recurse_submodules --stage
 207test_incompatible_with_recurse_submodules --killed
 208test_incompatible_with_recurse_submodules --unmerged
 209
 210test_done