9
test_expect_success 'setup test repository' '
10
git checkout -b base &&
11
12
+ # Make some objects that will only be reachable
13
+ # via non-commit tags.
14
+ mkdir child &&
15
+ echo file >child/file &&
16
+ git add child &&
17
+ git commit -m "will abandon" &&
18
+ git tag -a -m "tree" tree-tag HEAD^{tree} &&
19
+ echo file2 >file2 &&
20
+ git add file2 &&
21
+ git commit --amend -m "will abandon" &&
22
+ git tag tree-tag2 HEAD^{tree} &&
23
+
24
+ echo blob >file &&
25
+ blob_oid=$(git hash-object -t blob -w --stdin <file) &&
26
+ git tag -a -m "blob" blob-tag "$blob_oid" &&
27
+ echo blob2 >file2 &&
28
+ blob2_oid=$(git hash-object -t blob -w --stdin <file2) &&
29
+ git tag blob-tag2 "$blob2_oid" &&
30
+
31
+ rm -fr child file file2 &&
32
+
33
mkdir left &&
34
mkdir right &&
35
echo a >a &&
36
echo b >left/b &&
37
echo c >right/c &&
38
git add . &&
18
- git commit -m "first" &&
39
+ git commit --amend -m "first" &&
40
+ git tag -m "first" first HEAD &&
41
42
echo d >right/d &&
43
git add right &&
44
git commit -m "second" &&
45
+ git tag -a -m "second (under)" second.1 HEAD &&
46
+ git tag -a -m "second (top)" second.2 second.1 &&
47
48
+ # Set up file/dir collision in history.
49
+ rm a &&
50
+ mkdir a &&
51
+ echo a >a/a &&
52
echo bb >left/b &&
25
- git commit -a -m "third" &&
53
+ git add a left &&
54
+ git commit -m "third" &&
55
+ git tag -a -m "third" third &&
56
57
git checkout -b topic HEAD~1 &&
58
echo cc >right/c &&
29
- git commit -a -m "topic"
59
+ git commit -a -m "topic" &&
60
+ git tag -a -m "fourth" fourth
61
'
62
63
test_expect_success 'all' '
64
test-tool path-walk -- --all >out &&
65
66
+ cat >expect <<-EOF &&
67
+ 0:commit::$(git rev-parse topic)
68
+ 0:commit::$(git rev-parse base)
69
+ 0:commit::$(git rev-parse base~1)
70
+ 0:commit::$(git rev-parse base~2)
71
+ 1:tag:/tags:$(git rev-parse refs/tags/first)
72
+ 1:tag:/tags:$(git rev-parse refs/tags/second.1)
73
+ 1:tag:/tags:$(git rev-parse refs/tags/second.2)
74
+ 1:tag:/tags:$(git rev-parse refs/tags/third)
75
+ 1:tag:/tags:$(git rev-parse refs/tags/fourth)
76
+ 1:tag:/tags:$(git rev-parse refs/tags/tree-tag)
77
+ 1:tag:/tags:$(git rev-parse refs/tags/blob-tag)
78
+ 2:blob:/tagged-blobs:$(git rev-parse refs/tags/blob-tag^{})
79
+ 2:blob:/tagged-blobs:$(git rev-parse refs/tags/blob-tag2^{})
80
+ 3:tree::$(git rev-parse topic^{tree})
81
+ 3:tree::$(git rev-parse base^{tree})
82
+ 3:tree::$(git rev-parse base~1^{tree})
83
+ 3:tree::$(git rev-parse base~2^{tree})
84
+ 3:tree::$(git rev-parse refs/tags/tree-tag^{})
85
+ 3:tree::$(git rev-parse refs/tags/tree-tag2^{})
86
+ 4:blob:a:$(git rev-parse base~2:a)
87
+ 5:tree:right/:$(git rev-parse topic:right)
88
+ 5:tree:right/:$(git rev-parse base~1:right)
89
+ 5:tree:right/:$(git rev-parse base~2:right)
90
+ 6:blob:right/d:$(git rev-parse base~1:right/d)
91
+ 7:blob:right/c:$(git rev-parse base~2:right/c)
92
+ 7:blob:right/c:$(git rev-parse topic:right/c)
93
+ 8:tree:left/:$(git rev-parse base:left)
94
+ 8:tree:left/:$(git rev-parse base~2:left)
95
+ 9:blob:left/b:$(git rev-parse base~2:left/b)
96
+ 9:blob:left/b:$(git rev-parse base:left/b)
97
+ 10:tree:a/:$(git rev-parse base:a)
98
+ 11:blob:file2:$(git rev-parse refs/tags/tree-tag2^{}:file2)
99
+ 12:tree:child/:$(git rev-parse refs/tags/tree-tag:child)
100
+ 13:blob:child/file:$(git rev-parse refs/tags/tree-tag:child/file)
101
+ blobs:10
102
+ commits:4
103
+ tags:7
104
+ trees:13
105
+ EOF
106
+
107
+ test_cmp_sorted expect out
108
+'
109
+
110
+test_expect_success 'indexed objects' '
111
+ test_when_finished git reset --hard &&
112
+
113
+ # stage change into index, adding a blob but
114
+ # also invalidating the cache-tree for the root
115
+ # and the "left" directory.
116
+ echo bogus >left/c &&
117
+ git add left &&
118
+
119
+ test-tool path-walk -- --indexed-objects >out &&
120
+
121
+ cat >expect <<-EOF &&
122
+ 0:blob:a:$(git rev-parse HEAD:a)
123
+ 1:blob:left/b:$(git rev-parse HEAD:left/b)
124
+ 2:blob:left/c:$(git rev-parse :left/c)
125
+ 3:blob:right/c:$(git rev-parse HEAD:right/c)
126
+ 4:blob:right/d:$(git rev-parse HEAD:right/d)
127
+ 5:tree:right/:$(git rev-parse topic:right)
128
+ blobs:5
129
+ commits:0
130
+ tags:0
131
+ trees:1
132
+ EOF
133
+
134
+ test_cmp_sorted expect out
135
+'
136
+
137
+test_expect_success 'branches and indexed objects mix well' '
138
+ test_when_finished git reset --hard &&
139
+
140
+ # stage change into index, adding a blob but
141
+ # also invalidating the cache-tree for the root
142
+ # and the "right" directory.
143
+ echo fake >right/d &&
144
+ git add right &&
145
+
146
+ test-tool path-walk -- --indexed-objects --branches >out &&
147
+
148
cat >expect <<-EOF &&
149
0:commit::$(git rev-parse topic)
150
0:commit::$(git rev-parse base)
154
1:tree::$(git rev-parse base^{tree})
155
1:tree::$(git rev-parse base~1^{tree})
156
1:tree::$(git rev-parse base~2^{tree})
44
- 2:tree:right/:$(git rev-parse topic:right)
45
- 2:tree:right/:$(git rev-parse base~1:right)
46
- 2:tree:right/:$(git rev-parse base~2:right)
47
- 3:blob:right/d:$(git rev-parse base~1:right/d)
48
- 4:blob:right/c:$(git rev-parse base~2:right/c)
49
- 4:blob:right/c:$(git rev-parse topic:right/c)
50
- 5:tree:left/:$(git rev-parse base:left)
51
- 5:tree:left/:$(git rev-parse base~2:left)
52
- 6:blob:left/b:$(git rev-parse base~2:left/b)
53
- 6:blob:left/b:$(git rev-parse base:left/b)
54
- 7:blob:a:$(git rev-parse base~2:a)
55
- blobs:6
157
+ 2:blob:a:$(git rev-parse base~2:a)
158
+ 3:tree:right/:$(git rev-parse topic:right)
159
+ 3:tree:right/:$(git rev-parse base~1:right)
160
+ 3:tree:right/:$(git rev-parse base~2:right)
161
+ 4:blob:right/d:$(git rev-parse base~1:right/d)
162
+ 4:blob:right/d:$(git rev-parse :right/d)
163
+ 5:blob:right/c:$(git rev-parse base~2:right/c)
164
+ 5:blob:right/c:$(git rev-parse topic:right/c)
165
+ 6:tree:left/:$(git rev-parse base:left)
166
+ 6:tree:left/:$(git rev-parse base~2:left)
167
+ 7:blob:left/b:$(git rev-parse base:left/b)
168
+ 7:blob:left/b:$(git rev-parse base~2:left/b)
169
+ 8:tree:a/:$(git rev-parse refs/tags/third:a)
170
+ blobs:7
171
commits:4
57
- trees:9
172
+ tags:0
173
+ trees:10
174
EOF
175
176
test_cmp_sorted expect out
197
7:blob:a:$(git rev-parse base~2:a)
198
blobs:5
199
commits:3
200
+ tags:0
201
trees:7
202
EOF
203
218
7:blob:a:$(git rev-parse topic:a)
219
blobs:4
220
commits:1
221
+ tags:0
222
trees:3
223
EOF
224
230
-- topic --not base >out &&
231
232
cat >expect <<-EOF &&
115
- commits:0
116
- trees:0
233
0:blob:right/d:$(git rev-parse topic:right/d)
234
1:blob:right/c:$(git rev-parse topic:right/c)
235
2:blob:left/b:$(git rev-parse topic:left/b)
236
3:blob:a:$(git rev-parse topic:a)
237
blobs:4
238
+ commits:0
239
+ tags:0
240
+ trees:0
241
EOF
242
243
test_cmp_sorted expect out
252
cat >expect <<-EOF &&
253
0:commit::$(git rev-parse topic)
254
commits:1
136
- trees:0
255
blobs:0
256
+ tags:0
257
+ trees:0
258
EOF
259
260
test_cmp_sorted expect out
265
-- topic --not base >out &&
266
267
cat >expect <<-EOF &&
148
- commits:0
268
0:tree::$(git rev-parse topic^{tree})
269
1:tree:right/:$(git rev-parse topic:right)
270
2:tree:left/:$(git rev-parse topic:left)
152
- trees:3
271
+ commits:0
272
blobs:0
273
+ tags:0
274
+ trees:3
275
EOF
276
277
test_cmp_sorted expect out
295
7:blob:a:$(git rev-parse base~1:a)
296
blobs:5
297
commits:2
298
+ tags:0
299
trees:5
300
EOF
301
302
test_cmp_sorted expect out
303
'
304
305
+test_expect_success 'trees are reported exactly once' '
306
+ test_when_finished "rm -rf unique-trees" &&
307
+ test_create_repo unique-trees &&
308
+ (
309
+ cd unique-trees &&
310
+ mkdir initial &&
311
+ test_commit initial/file &&
312
+
313
+ git switch -c move-to-top &&
314
+ git mv initial/file.t ./ &&
315
+ test_tick &&
316
+ git commit -m moved &&
317
+
318
+ git update-ref refs/heads/other HEAD
319
+ ) &&
320
+
321
+ test-tool -C unique-trees path-walk -- --all >out &&
322
+ tree=$(git -C unique-trees rev-parse HEAD:) &&
323
+ grep "$tree" out >out-filtered &&
324
+ test_line_count = 1 out-filtered
325
+'
326
+
327
test_done