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