list-objects: consume sparse tree walk
[git] / t / t5322-pack-objects-sparse.sh
1 #!/bin/sh
2
3 test_description='pack-objects object selection using sparse algorithm'
4 . ./test-lib.sh
5
6 test_expect_success 'setup repo' '
7         test_commit initial &&
8         for i in $(test_seq 1 3)
9         do
10                 mkdir f$i &&
11                 for j in $(test_seq 1 3)
12                 do
13                         mkdir f$i/f$j &&
14                         echo $j >f$i/f$j/data.txt
15                 done
16         done &&
17         git add . &&
18         git commit -m "Initialized trees" &&
19         for i in $(test_seq 1 3)
20         do
21                 git checkout -b topic$i master &&
22                 echo change-$i >f$i/f$i/data.txt &&
23                 git commit -a -m "Changed f$i/f$i/data.txt"
24         done &&
25         cat >packinput.txt <<-EOF &&
26         topic1
27         ^topic2
28         ^topic3
29         EOF
30         git rev-parse                   \
31                 topic1                  \
32                 topic1^{tree}           \
33                 topic1:f1               \
34                 topic1:f1/f1            \
35                 topic1:f1/f1/data.txt | sort >expect_objects.txt
36 '
37
38 test_expect_success 'non-sparse pack-objects' '
39         git pack-objects --stdout --revs <packinput.txt >nonsparse.pack &&
40         git index-pack -o nonsparse.idx nonsparse.pack &&
41         git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
42         test_cmp expect_objects.txt nonsparse_objects.txt
43 '
44
45 test_expect_success 'sparse pack-objects' '
46         git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
47         git index-pack -o sparse.idx sparse.pack &&
48         git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
49         test_cmp expect_objects.txt sparse_objects.txt
50 '
51
52 test_expect_success 'duplicate a folder from f3 and commit to topic1' '
53         git checkout topic1 &&
54         echo change-3 >f3/f3/data.txt &&
55         git commit -a -m "Changed f3/f3/data.txt" &&
56         git rev-parse                   \
57                 topic1~1                \
58                 topic1~1^{tree}         \
59                 topic1^{tree}           \
60                 topic1                  \
61                 topic1:f1               \
62                 topic1:f1/f1            \
63                 topic1:f1/f1/data.txt | sort >required_objects.txt
64 '
65
66 test_expect_success 'non-sparse pack-objects' '
67         git pack-objects --stdout --revs <packinput.txt >nonsparse.pack &&
68         git index-pack -o nonsparse.idx nonsparse.pack &&
69         git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
70         comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
71         test_cmp required_objects.txt nonsparse_required_objects.txt
72 '
73
74 test_expect_success 'sparse pack-objects' '
75         git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
76         git index-pack -o sparse.idx sparse.pack &&
77         git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
78         comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt &&
79         test_cmp required_objects.txt sparse_required_objects.txt
80 '
81
82 test_expect_success 'duplicate a folder from f1 into f3' '
83         mkdir f3/f4 &&
84         cp -r f1/f1/* f3/f4 &&
85         git add f3/f4 &&
86         git commit -m "Copied f1/f1 to f3/f4" &&
87         cat >packinput.txt <<-EOF &&
88         topic1
89         ^topic1~1
90         EOF
91         git rev-parse           \
92                 topic1          \
93                 topic1^{tree}   \
94                 topic1:f3 | sort >required_objects.txt
95 '
96
97 test_expect_success 'non-sparse pack-objects' '
98         git pack-objects --stdout --revs <packinput.txt >nonsparse.pack &&
99         git index-pack -o nonsparse.idx nonsparse.pack &&
100         git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
101         comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
102         test_cmp required_objects.txt nonsparse_required_objects.txt
103 '
104
105 test_expect_success 'sparse pack-objects' '
106         git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
107         git index-pack -o sparse.idx sparse.pack &&
108         git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
109         comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt &&
110         test_cmp required_objects.txt sparse_required_objects.txt
111 '
112
113 test_done