t: add test functions to translate hash-related values
[git/raj.git] / t / t6112-rev-list-filters-objects.sh
blobd4ff0b3bef61b5d3de1ab0fad4695949d80dc8fd
1 #!/bin/sh
3 test_description='git rev-list using object filtering'
5 . ./test-lib.sh
7 # Test the blob:none filter.
9 test_expect_success 'setup r1' '
10 echo "{print \$1}" >print_1.awk &&
11 echo "{print \$2}" >print_2.awk &&
13 git init r1 &&
14 for n in 1 2 3 4 5
16 echo "This is file: $n" > r1/file.$n
17 git -C r1 add file.$n
18 git -C r1 commit -m "$n"
19 done
22 test_expect_success 'verify blob:none omits all 5 blobs' '
23 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
24 | awk -f print_2.awk \
25 | sort >expected &&
26 git -C r1 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:none \
27 | awk -f print_1.awk \
28 | sed "s/~//" \
29 | sort >observed &&
30 test_cmp observed expected
33 test_expect_success 'verify emitted+omitted == all' '
34 git -C r1 rev-list HEAD --objects \
35 | awk -f print_1.awk \
36 | sort >expected &&
37 git -C r1 rev-list HEAD --objects --filter-print-omitted --filter=blob:none \
38 | awk -f print_1.awk \
39 | sed "s/~//" \
40 | sort >observed &&
41 test_cmp observed expected
45 # Test blob:limit=<n>[kmg] filter.
46 # We boundary test around the size parameter. The filter is strictly less than
47 # the value, so size 500 and 1000 should have the same results, but 1001 should
48 # filter more.
50 test_expect_success 'setup r2' '
51 git init r2 &&
52 for n in 1000 10000
54 printf "%"$n"s" X > r2/large.$n
55 git -C r2 add large.$n
56 git -C r2 commit -m "$n"
57 done
60 test_expect_success 'verify blob:limit=500 omits all blobs' '
61 git -C r2 ls-files -s large.1000 large.10000 \
62 | awk -f print_2.awk \
63 | sort >expected &&
64 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=500 \
65 | awk -f print_1.awk \
66 | sed "s/~//" \
67 | sort >observed &&
68 test_cmp observed expected
71 test_expect_success 'verify emitted+omitted == all' '
72 git -C r2 rev-list HEAD --objects \
73 | awk -f print_1.awk \
74 | sort >expected &&
75 git -C r2 rev-list HEAD --objects --filter-print-omitted --filter=blob:limit=500 \
76 | awk -f print_1.awk \
77 | sed "s/~//" \
78 | sort >observed &&
79 test_cmp observed expected
82 test_expect_success 'verify blob:limit=1000' '
83 git -C r2 ls-files -s large.1000 large.10000 \
84 | awk -f print_2.awk \
85 | sort >expected &&
86 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1000 \
87 | awk -f print_1.awk \
88 | sed "s/~//" \
89 | sort >observed &&
90 test_cmp observed expected
93 test_expect_success 'verify blob:limit=1001' '
94 git -C r2 ls-files -s large.10000 \
95 | awk -f print_2.awk \
96 | sort >expected &&
97 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1001 \
98 | awk -f print_1.awk \
99 | sed "s/~//" \
100 | sort >observed &&
101 test_cmp observed expected
104 test_expect_success 'verify blob:limit=1k' '
105 git -C r2 ls-files -s large.10000 \
106 | awk -f print_2.awk \
107 | sort >expected &&
108 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1k \
109 | awk -f print_1.awk \
110 | sed "s/~//" \
111 | sort >observed &&
112 test_cmp observed expected
115 test_expect_success 'verify blob:limit=1m' '
116 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1m \
117 | awk -f print_1.awk \
118 | sed "s/~//" \
119 | sort >observed &&
120 test_must_be_empty observed
123 # Test sparse:path=<path> filter.
124 # Use a local file containing a sparse-checkout specification to filter
125 # out blobs not required for the corresponding sparse-checkout. We do not
126 # require sparse-checkout to actually be enabled.
128 test_expect_success 'setup r3' '
129 git init r3 &&
130 mkdir r3/dir1 &&
131 for n in sparse1 sparse2
133 echo "This is file: $n" > r3/$n
134 git -C r3 add $n
135 echo "This is file: dir1/$n" > r3/dir1/$n
136 git -C r3 add dir1/$n
137 done &&
138 git -C r3 commit -m "sparse" &&
139 echo dir1/ >pattern1 &&
140 echo sparse1 >pattern2
143 test_expect_success 'verify sparse:path=pattern1 omits top-level files' '
144 git -C r3 ls-files -s sparse1 sparse2 \
145 | awk -f print_2.awk \
146 | sort >expected &&
147 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern1 \
148 | awk -f print_1.awk \
149 | sed "s/~//" \
150 | sort >observed &&
151 test_cmp observed expected
154 test_expect_success 'verify sparse:path=pattern2 omits both sparse2 files' '
155 git -C r3 ls-files -s sparse2 dir1/sparse2 \
156 | awk -f print_2.awk \
157 | sort >expected &&
158 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern2 \
159 | awk -f print_1.awk \
160 | sed "s/~//" \
161 | sort >observed &&
162 test_cmp observed expected
165 # Test sparse:oid=<oid-ish> filter.
166 # Like sparse:path, but we get the sparse-checkout specification from
167 # a blob rather than a file on disk.
169 test_expect_success 'setup r3 part 2' '
170 echo dir1/ >r3/pattern &&
171 git -C r3 add pattern &&
172 git -C r3 commit -m "pattern"
175 test_expect_success 'verify sparse:oid=OID omits top-level files' '
176 git -C r3 ls-files -s pattern sparse1 sparse2 \
177 | awk -f print_2.awk \
178 | sort >expected &&
179 oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
180 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=$oid \
181 | awk -f print_1.awk \
182 | sed "s/~//" \
183 | sort >observed &&
184 test_cmp observed expected
187 test_expect_success 'verify sparse:oid=oid-ish omits top-level files' '
188 git -C r3 ls-files -s pattern sparse1 sparse2 \
189 | awk -f print_2.awk \
190 | sort >expected &&
191 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=master:pattern \
192 | awk -f print_1.awk \
193 | sed "s/~//" \
194 | sort >observed &&
195 test_cmp observed expected
198 # Delete some loose objects and use rev-list, but WITHOUT any filtering.
199 # This models previously omitted objects that we did not receive.
201 test_expect_success 'rev-list W/ --missing=print' '
202 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
203 | awk -f print_2.awk \
204 | sort >expected &&
205 for id in `cat expected | sed "s|..|&/|"`
207 rm r1/.git/objects/$id
208 done &&
209 git -C r1 rev-list --quiet HEAD --missing=print --objects \
210 | awk -f print_1.awk \
211 | sed "s/?//" \
212 | sort >observed &&
213 test_cmp observed expected
216 test_expect_success 'rev-list W/O --missing fails' '
217 test_must_fail git -C r1 rev-list --quiet --objects HEAD
220 test_expect_success 'rev-list W/ missing=allow-any' '
221 git -C r1 rev-list --quiet --missing=allow-any --objects HEAD
224 test_done