maintenance: use pointers to check --auto
[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 --no-sparse <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 --no-sparse <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 # Demonstrate that the algorithms differ when we copy a tree wholesale
83 # from one folder to another.
84
85 test_expect_success 'duplicate a folder from f1 into f3' '
86         mkdir f3/f4 &&
87         cp -r f1/f1/* f3/f4 &&
88         git add f3/f4 &&
89         git commit -m "Copied f1/f1 to f3/f4" &&
90         cat >packinput.txt <<-EOF &&
91         topic1
92         ^topic1~1
93         EOF
94         git rev-parse           \
95                 topic1          \
96                 topic1^{tree}   \
97                 topic1:f3 | sort >required_objects.txt
98 '
99
100 test_expect_success 'non-sparse pack-objects' '
101         git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
102         git index-pack -o nonsparse.idx nonsparse.pack &&
103         git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
104         comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
105         test_cmp required_objects.txt nonsparse_required_objects.txt
106 '
107
108 # --sparse is enabled by default by pack.useSparse
109 test_expect_success 'sparse pack-objects' '
110         GIT_TEST_PACK_SPARSE=-1 &&
111         git rev-parse                   \
112                 topic1                  \
113                 topic1^{tree}           \
114                 topic1:f3               \
115                 topic1:f3/f4            \
116                 topic1:f3/f4/data.txt | sort >expect_sparse_objects.txt &&
117         git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
118         git index-pack -o sparse.idx sparse.pack &&
119         git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
120         test_cmp expect_sparse_objects.txt sparse_objects.txt
121 '
122
123 test_expect_success 'pack.useSparse enables algorithm' '
124         git config pack.useSparse true &&
125         git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
126         git index-pack -o sparse.idx sparse.pack &&
127         git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
128         test_cmp expect_sparse_objects.txt sparse_objects.txt
129 '
130
131 test_expect_success 'pack.useSparse overridden' '
132         git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack &&
133         git index-pack -o sparse.idx sparse.pack &&
134         git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
135         test_cmp required_objects.txt sparse_objects.txt
136 '
137
138 test_done