about summary refs log tree commit diff
path: root/t/t6130-pathspec-noglob.sh
blob: ba7902c9cdcd0e6664f81b478b24596a4deb06dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/sh

test_description='test globbing (and noglob) of pathspec limiting'
. ./test-lib.sh

test_expect_success 'create commits with glob characters' '
	test_commit unrelated bar &&
	test_commit vanilla foo &&
	# insert file "f*" in the commit, but in a way that avoids
	# the name "f*" in the worktree, because it is not allowed
	# on Windows (the tests below do not depend on the presence
	# of the file in the worktree)
	git config core.protectNTFS false &&
	git update-index --add --cacheinfo 100644 "$(git rev-parse HEAD:foo)" "f*" &&
	test_tick &&
	git commit -m star &&
	test_commit bracket "f[o][o]"
'

test_expect_success 'vanilla pathspec matches literally' '
	echo vanilla >expect &&
	git log --format=%s -- foo >actual &&
	test_cmp expect actual
'

test_expect_success 'star pathspec globs' '
	cat >expect <<-\EOF &&
	bracket
	star
	vanilla
	EOF
	git log --format=%s -- "f*" >actual &&
	test_cmp expect actual
'

test_expect_success 'star pathspec globs' '
	cat >expect <<-\EOF &&
	bracket
	star
	vanilla
	EOF
	git log --format=%s -- ":(glob)f*" >actual &&
	test_cmp expect actual
'

test_expect_success 'bracket pathspec globs and matches literal brackets' '
	cat >expect <<-\EOF &&
	bracket
	vanilla
	EOF
	git log --format=%s -- "f[o][o]" >actual &&
	test_cmp expect actual
'

test_expect_success 'bracket pathspec globs and matches literal brackets' '
	cat >expect <<-\EOF &&
	bracket
	vanilla
	EOF
	git log --format=%s -- ":(glob)f[o][o]" >actual &&
	test_cmp expect actual
'

test_expect_success 'no-glob option matches literally (vanilla)' '
	echo vanilla >expect &&
	git --literal-pathspecs log --format=%s -- foo >actual &&
	test_cmp expect actual
'

test_expect_success 'no-glob option matches literally (vanilla)' '
	echo vanilla >expect &&
	git log --format=%s -- ":(literal)foo" >actual &&
	test_cmp expect actual
'

test_expect_success 'no-glob option matches literally (star)' '
	echo star >expect &&
	git --literal-pathspecs log --format=%s -- "f*" >actual &&
	test_cmp expect actual
'

test_expect_success 'no-glob option matches literally (star)' '
	echo star >expect &&
	git log --format=%s -- ":(literal)f*" >actual &&
	test_cmp expect actual
'

test_expect_success 'no-glob option matches literally (bracket)' '
	echo bracket >expect &&
	git --literal-pathspecs log --format=%s -- "f[o][o]" >actual &&
	test_cmp expect actual
'

test_expect_success 'no-glob option matches literally (bracket)' '
	echo bracket >expect &&
	git log --format=%s -- ":(literal)f[o][o]" >actual &&
	test_cmp expect actual
'

test_expect_success 'no-glob option disables :(literal)' '
	git --literal-pathspecs log --format=%s -- ":(literal)foo" >actual &&
	test_must_be_empty actual
'

test_expect_success 'no-glob environment variable works' '
	echo star >expect &&
	GIT_LITERAL_PATHSPECS=1 git log --format=%s -- "f*" >actual &&
	test_cmp expect actual
'

test_expect_success 'blame takes global pathspec flags' '
	git --literal-pathspecs blame -- foo &&
	git --icase-pathspecs   blame -- foo &&
	git --glob-pathspecs    blame -- foo &&
	git --noglob-pathspecs  blame -- foo
'

test_expect_success 'setup xxx/bar' '
	mkdir xxx &&
	test_commit xxx xxx/bar
'

test_expect_success '**/ works with :(glob)' '
	cat >expect <<-\EOF &&
	xxx
	unrelated
	EOF
	git log --format=%s -- ":(glob)**/bar" >actual &&
	test_cmp expect actual
'

test_expect_success '**/ does not work with --noglob-pathspecs' '
	git --noglob-pathspecs log --format=%s -- "**/bar" >actual &&
	test_must_be_empty actual
'

test_expect_success '**/ works with :(glob) and --noglob-pathspecs' '
	cat >expect <<-\EOF &&
	xxx
	unrelated
	EOF
	git --noglob-pathspecs log --format=%s -- ":(glob)**/bar" >actual &&
	test_cmp expect actual
'

test_expect_success '**/ works with --glob-pathspecs' '
	cat >expect <<-\EOF &&
	xxx
	unrelated
	EOF
	git --glob-pathspecs log --format=%s -- "**/bar" >actual &&
	test_cmp expect actual
'

test_expect_success '**/ does not work with :(literal) and --glob-pathspecs' '
	git --glob-pathspecs log --format=%s -- ":(literal)**/bar" >actual &&
	test_must_be_empty actual
'

test_done