t / t6135-pathspec-with-attrs.shon commit t4045: abstract away SHA-1-specific constants (5c02428)
   1#!/bin/sh
   2
   3test_description='test labels in pathspecs'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup a tree' '
   7        cat <<-\EOF >expect &&
   8        fileA
   9        fileAB
  10        fileAC
  11        fileB
  12        fileBC
  13        fileC
  14        fileNoLabel
  15        fileSetLabel
  16        fileUnsetLabel
  17        fileValue
  18        fileWrongLabel
  19        sub/fileA
  20        sub/fileAB
  21        sub/fileAC
  22        sub/fileB
  23        sub/fileBC
  24        sub/fileC
  25        sub/fileNoLabel
  26        sub/fileSetLabel
  27        sub/fileUnsetLabel
  28        sub/fileValue
  29        sub/fileWrongLabel
  30        EOF
  31        mkdir sub &&
  32        while read path
  33        do
  34                : >$path &&
  35                git add $path || return 1
  36        done <expect &&
  37        git commit -m "initial commit" &&
  38        git ls-files >actual &&
  39        test_cmp expect actual
  40'
  41
  42test_expect_success 'pathspec with no attr' '
  43        test_must_fail git ls-files ":(attr:)"
  44'
  45
  46test_expect_success 'pathspec with labels and non existent .gitattributes' '
  47        git ls-files ":(attr:label)" >actual &&
  48        test_must_be_empty actual
  49'
  50
  51test_expect_success 'setup .gitattributes' '
  52        cat <<-\EOF >.gitattributes &&
  53        fileA labelA
  54        fileB labelB
  55        fileC labelC
  56        fileAB labelA labelB
  57        fileAC labelA labelC
  58        fileBC labelB labelC
  59        fileUnsetLabel -label
  60        fileSetLabel label
  61        fileValue label=foo
  62        fileWrongLabel label☺
  63        EOF
  64        git add .gitattributes &&
  65        git commit -m "add attributes"
  66'
  67
  68test_expect_success 'check specific set attr' '
  69        cat <<-\EOF >expect &&
  70        fileSetLabel
  71        sub/fileSetLabel
  72        EOF
  73        git ls-files ":(attr:label)" >actual &&
  74        test_cmp expect actual
  75'
  76
  77test_expect_success 'check specific unset attr' '
  78        cat <<-\EOF >expect &&
  79        fileUnsetLabel
  80        sub/fileUnsetLabel
  81        EOF
  82        git ls-files ":(attr:-label)" >actual &&
  83        test_cmp expect actual
  84'
  85
  86test_expect_success 'check specific value attr' '
  87        cat <<-\EOF >expect &&
  88        fileValue
  89        sub/fileValue
  90        EOF
  91        git ls-files ":(attr:label=foo)" >actual &&
  92        test_cmp expect actual &&
  93        git ls-files ":(attr:label=bar)" >actual &&
  94        test_must_be_empty actual
  95'
  96
  97test_expect_success 'check unspecified attr' '
  98        cat <<-\EOF >expect &&
  99        .gitattributes
 100        fileA
 101        fileAB
 102        fileAC
 103        fileB
 104        fileBC
 105        fileC
 106        fileNoLabel
 107        fileWrongLabel
 108        sub/fileA
 109        sub/fileAB
 110        sub/fileAC
 111        sub/fileB
 112        sub/fileBC
 113        sub/fileC
 114        sub/fileNoLabel
 115        sub/fileWrongLabel
 116        EOF
 117        git ls-files ":(attr:!label)" >actual &&
 118        test_cmp expect actual
 119'
 120
 121test_expect_success 'check multiple unspecified attr' '
 122        cat <<-\EOF >expect &&
 123        .gitattributes
 124        fileC
 125        fileNoLabel
 126        fileWrongLabel
 127        sub/fileC
 128        sub/fileNoLabel
 129        sub/fileWrongLabel
 130        EOF
 131        git ls-files ":(attr:!labelB !labelA !label)" >actual &&
 132        test_cmp expect actual
 133'
 134
 135test_expect_success 'check label with more labels but excluded path' '
 136        cat <<-\EOF >expect &&
 137        fileAB
 138        fileB
 139        fileBC
 140        EOF
 141        git ls-files ":(attr:labelB)" ":(exclude)sub/" >actual &&
 142        test_cmp expect actual
 143'
 144
 145test_expect_success 'check label excluding other labels' '
 146        cat <<-\EOF >expect &&
 147        fileAB
 148        fileB
 149        fileBC
 150        sub/fileAB
 151        sub/fileB
 152        EOF
 153        git ls-files ":(attr:labelB)" ":(exclude,attr:labelC)sub/" >actual &&
 154        test_cmp expect actual
 155'
 156
 157test_expect_success 'fail on multiple attr specifiers in one pathspec item' '
 158        test_must_fail git ls-files . ":(attr:labelB,attr:labelC)" 2>actual &&
 159        test_i18ngrep "Only one" actual
 160'
 161
 162test_expect_success 'fail if attr magic is used places not implemented' '
 163        # The main purpose of this test is to check that we actually fail
 164        # when you attempt to use attr magic in commands that do not implement
 165        # attr magic. This test does not advocate git-add to stay that way,
 166        # though, but git-add is convenient as it has its own internal pathspec
 167        # parsing.
 168        test_must_fail git add ":(attr:labelB)" 2>actual &&
 169        test_i18ngrep "unsupported magic" actual
 170'
 171
 172test_expect_success 'abort on giving invalid label on the command line' '
 173        test_must_fail git ls-files . ":(attr:☺)"
 174'
 175
 176test_expect_success 'abort on asking for wrong magic' '
 177        test_must_fail git ls-files . ":(attr:-label=foo)" &&
 178        test_must_fail git ls-files . ":(attr:!label=foo)"
 179'
 180
 181test_expect_success 'check attribute list' '
 182        cat <<-EOF >>.gitattributes &&
 183        * whitespace=indent,trail,space
 184        EOF
 185        git ls-files ":(attr:whitespace=indent\,trail\,space)" >actual &&
 186        git ls-files >expect &&
 187        test_cmp expect actual
 188'
 189
 190test_expect_success 'backslash cannot be the last character' '
 191        test_must_fail git ls-files ":(attr:label=foo\\ labelA=bar)" 2>actual &&
 192        test_i18ngrep "not allowed as last character in attr value" actual
 193'
 194
 195test_expect_success 'backslash cannot be used as a value' '
 196        test_must_fail git ls-files ":(attr:label=f\\\oo)" 2>actual &&
 197        test_i18ngrep "for value matching" actual
 198'
 199
 200test_done