| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test globbing (and noglob) of pathspec limiting' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'create commits with glob characters' ' |
| 8 | test_commit unrelated bar && |
| 9 | test_commit vanilla foo && |
| 10 | # insert file "f*" in the commit, but in a way that avoids |
| 11 | # the name "f*" in the worktree, because it is not allowed |
| 12 | # on Windows (the tests below do not depend on the presence |
| 13 | # of the file in the worktree) |
| 14 | git config core.protectNTFS false && |
| 15 | git update-index --add --cacheinfo 100644 "$(git rev-parse HEAD:foo)" "f*" && |
| 16 | test_tick && |
| 17 | git commit -m star && |
| 18 | test_commit bracket "f[o][o]" |
| 19 | ' |
| 20 | |
| 21 | test_expect_success 'vanilla pathspec matches literally' ' |
| 22 | echo vanilla >expect && |
| 23 | git log --format=%s -- foo >actual && |
| 24 | test_cmp expect actual |
| 25 | ' |
| 26 | |
| 27 | test_expect_success 'star pathspec globs' ' |
| 28 | cat >expect <<-\EOF && |
| 29 | bracket |
| 30 | star |
| 31 | vanilla |
| 32 | EOF |
| 33 | git log --format=%s -- "f*" >actual && |
| 34 | test_cmp expect actual |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'star pathspec globs' ' |
| 38 | cat >expect <<-\EOF && |
| 39 | bracket |
| 40 | star |
| 41 | vanilla |
| 42 | EOF |
| 43 | git log --format=%s -- ":(glob)f*" >actual && |
| 44 | test_cmp expect actual |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'bracket pathspec globs and matches literal brackets' ' |
| 48 | cat >expect <<-\EOF && |
| 49 | bracket |
| 50 | vanilla |
| 51 | EOF |
| 52 | git log --format=%s -- "f[o][o]" >actual && |
| 53 | test_cmp expect actual |
| 54 | ' |
| 55 | |
| 56 | test_expect_success 'bracket pathspec globs and matches literal brackets' ' |
| 57 | cat >expect <<-\EOF && |
| 58 | bracket |
| 59 | vanilla |
| 60 | EOF |
| 61 | git log --format=%s -- ":(glob)f[o][o]" >actual && |
| 62 | test_cmp expect actual |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'no-glob option matches literally (vanilla)' ' |
| 66 | echo vanilla >expect && |
| 67 | git --literal-pathspecs log --format=%s -- foo >actual && |
| 68 | test_cmp expect actual |
| 69 | ' |
| 70 | |
| 71 | test_expect_success 'no-glob option matches literally (vanilla)' ' |
| 72 | echo vanilla >expect && |
| 73 | git log --format=%s -- ":(literal)foo" >actual && |
| 74 | test_cmp expect actual |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'no-glob option matches literally (star)' ' |
| 78 | echo star >expect && |
| 79 | git --literal-pathspecs log --format=%s -- "f*" >actual && |
| 80 | test_cmp expect actual |
| 81 | ' |
| 82 | |
| 83 | test_expect_success 'no-glob option matches literally (star)' ' |
| 84 | echo star >expect && |
| 85 | git log --format=%s -- ":(literal)f*" >actual && |
| 86 | test_cmp expect actual |
| 87 | ' |
| 88 | |
| 89 | test_expect_success 'no-glob option matches literally (bracket)' ' |
| 90 | echo bracket >expect && |
| 91 | git --literal-pathspecs log --format=%s -- "f[o][o]" >actual && |
| 92 | test_cmp expect actual |
| 93 | ' |
| 94 | |
| 95 | test_expect_success 'no-glob option matches literally (bracket)' ' |
| 96 | echo bracket >expect && |
| 97 | git log --format=%s -- ":(literal)f[o][o]" >actual && |
| 98 | test_cmp expect actual |
| 99 | ' |
| 100 | |
| 101 | test_expect_success 'no-glob option disables :(literal)' ' |
| 102 | git --literal-pathspecs log --format=%s -- ":(literal)foo" >actual && |
| 103 | test_must_be_empty actual |
| 104 | ' |
| 105 | |
| 106 | test_expect_success 'no-glob environment variable works' ' |
| 107 | echo star >expect && |
| 108 | GIT_LITERAL_PATHSPECS=1 git log --format=%s -- "f*" >actual && |
| 109 | test_cmp expect actual |
| 110 | ' |
| 111 | |
| 112 | test_expect_success 'blame takes global pathspec flags' ' |
| 113 | git --literal-pathspecs blame -- foo && |
| 114 | git --icase-pathspecs blame -- foo && |
| 115 | git --glob-pathspecs blame -- foo && |
| 116 | git --noglob-pathspecs blame -- foo |
| 117 | ' |
| 118 | |
| 119 | test_expect_success 'setup xxx/bar' ' |
| 120 | mkdir xxx && |
| 121 | test_commit xxx xxx/bar |
| 122 | ' |
| 123 | |
| 124 | test_expect_success '**/ works with :(glob)' ' |
| 125 | cat >expect <<-\EOF && |
| 126 | xxx |
| 127 | unrelated |
| 128 | EOF |
| 129 | git log --format=%s -- ":(glob)**/bar" >actual && |
| 130 | test_cmp expect actual |
| 131 | ' |
| 132 | |
| 133 | test_expect_success '**/ does not work with --noglob-pathspecs' ' |
| 134 | git --noglob-pathspecs log --format=%s -- "**/bar" >actual && |
| 135 | test_must_be_empty actual |
| 136 | ' |
| 137 | |
| 138 | test_expect_success '**/ works with :(glob) and --noglob-pathspecs' ' |
| 139 | cat >expect <<-\EOF && |
| 140 | xxx |
| 141 | unrelated |
| 142 | EOF |
| 143 | git --noglob-pathspecs log --format=%s -- ":(glob)**/bar" >actual && |
| 144 | test_cmp expect actual |
| 145 | ' |
| 146 | |
| 147 | test_expect_success '**/ works with --glob-pathspecs' ' |
| 148 | cat >expect <<-\EOF && |
| 149 | xxx |
| 150 | unrelated |
| 151 | EOF |
| 152 | git --glob-pathspecs log --format=%s -- "**/bar" >actual && |
| 153 | test_cmp expect actual |
| 154 | ' |
| 155 | |
| 156 | test_expect_success '**/ does not work with :(literal) and --glob-pathspecs' ' |
| 157 | git --glob-pathspecs log --format=%s -- ":(literal)**/bar" >actual && |
| 158 | test_must_be_empty actual |
| 159 | ' |
| 160 | |
| 161 | test_done |