Merge branch 'ds/reprepare-alternates-when-repreparing-packfiles'
[alt-git.git] / t / t5322-pack-objects-sparse.sh
blob770695c9278292285f7c5ed2fd65a80d7169d92f
1 #!/bin/sh
3 test_description='pack-objects object selection using sparse algorithm'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success 'setup repo' '
11 test_commit initial &&
12 for i in $(test_seq 1 3)
14 mkdir f$i &&
15 for j in $(test_seq 1 3)
17 mkdir f$i/f$j &&
18 echo $j >f$i/f$j/data.txt || return 1
19 done
20 done &&
21 git add . &&
22 git commit -m "Initialized trees" &&
23 for i in $(test_seq 1 3)
25 git checkout -b topic$i main &&
26 echo change-$i >f$i/f$i/data.txt &&
27 git commit -a -m "Changed f$i/f$i/data.txt" || return 1
28 done &&
29 cat >packinput.txt <<-EOF &&
30 topic1
31 ^topic2
32 ^topic3
33 EOF
34 git rev-parse \
35 topic1 \
36 topic1^{tree} \
37 topic1:f1 \
38 topic1:f1/f1 \
39 topic1:f1/f1/data.txt | sort >expect_objects.txt
42 test_expect_success 'non-sparse pack-objects' '
43 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
44 git index-pack -o nonsparse.idx nonsparse.pack &&
45 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
46 test_cmp expect_objects.txt nonsparse_objects.txt
49 test_expect_success 'sparse pack-objects' '
50 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
51 git index-pack -o sparse.idx sparse.pack &&
52 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
53 test_cmp expect_objects.txt sparse_objects.txt
56 test_expect_success 'duplicate a folder from f3 and commit to topic1' '
57 git checkout topic1 &&
58 echo change-3 >f3/f3/data.txt &&
59 git commit -a -m "Changed f3/f3/data.txt" &&
60 git rev-parse \
61 topic1~1 \
62 topic1~1^{tree} \
63 topic1^{tree} \
64 topic1 \
65 topic1:f1 \
66 topic1:f1/f1 \
67 topic1:f1/f1/data.txt | sort >required_objects.txt
70 test_expect_success 'non-sparse pack-objects' '
71 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
72 git index-pack -o nonsparse.idx nonsparse.pack &&
73 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
74 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
75 test_cmp required_objects.txt nonsparse_required_objects.txt
78 test_expect_success 'sparse pack-objects' '
79 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack &&
80 git index-pack -o sparse.idx sparse.pack &&
81 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
82 comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt &&
83 test_cmp required_objects.txt sparse_required_objects.txt
86 # Demonstrate that the algorithms differ when we copy a tree wholesale
87 # from one folder to another.
89 test_expect_success 'duplicate a folder from f1 into f3' '
90 mkdir f3/f4 &&
91 cp -r f1/f1/* f3/f4 &&
92 git add f3/f4 &&
93 git commit -m "Copied f1/f1 to f3/f4" &&
94 cat >packinput.txt <<-EOF &&
95 topic1
96 ^topic1~1
97 EOF
98 git rev-parse \
99 topic1 \
100 topic1^{tree} \
101 topic1:f3 | sort >required_objects.txt
104 test_expect_success 'non-sparse pack-objects' '
105 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack &&
106 git index-pack -o nonsparse.idx nonsparse.pack &&
107 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt &&
108 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt &&
109 test_cmp required_objects.txt nonsparse_required_objects.txt
112 # --sparse is enabled by default by pack.useSparse
113 test_expect_success 'sparse pack-objects' '
114 GIT_TEST_PACK_SPARSE=-1 &&
115 git rev-parse \
116 topic1 \
117 topic1^{tree} \
118 topic1:f3 \
119 topic1:f3/f4 \
120 topic1:f3/f4/data.txt | sort >expect_sparse_objects.txt &&
121 git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
122 git index-pack -o sparse.idx sparse.pack &&
123 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
124 test_cmp expect_sparse_objects.txt sparse_objects.txt
127 test_expect_success 'pack.useSparse enables algorithm' '
128 git config pack.useSparse true &&
129 git pack-objects --stdout --revs <packinput.txt >sparse.pack &&
130 git index-pack -o sparse.idx sparse.pack &&
131 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
132 test_cmp expect_sparse_objects.txt sparse_objects.txt
135 test_expect_success 'pack.useSparse overridden' '
136 git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack &&
137 git index-pack -o sparse.idx sparse.pack &&
138 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt &&
139 test_cmp required_objects.txt sparse_objects.txt
142 test_done