]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7701-repack-unpack-unreachable.sh
hashmap: use *_entry APIs for iteration
[thirdparty/git.git] / t / t7701-repack-unpack-unreachable.sh
CommitLineData
ccc12972
BC
1#!/bin/sh
2
47a528ad 3test_description='git repack works correctly'
ccc12972
BC
4
5. ./test-lib.sh
6
e896912c
BC
7fsha1=
8csha1=
9tsha1=
10
83d0289d 11test_expect_success '-A with -d option leaves unreachable objects unpacked' '
ccc12972
BC
12 echo content > file1 &&
13 git add . &&
713c79e8 14 test_tick &&
ccc12972
BC
15 git commit -m initial_commit &&
16 # create a transient branch with unique content
17 git checkout -b transient_branch &&
18 echo more content >> file1 &&
19 # record the objects created in the database for file, commit, tree
20 fsha1=$(git hash-object file1) &&
713c79e8 21 test_tick &&
ccc12972
BC
22 git commit -a -m more_content &&
23 csha1=$(git rev-parse HEAD^{commit}) &&
24 tsha1=$(git rev-parse HEAD^{tree}) &&
25 git checkout master &&
26 echo even more content >> file1 &&
713c79e8 27 test_tick &&
ccc12972
BC
28 git commit -a -m even_more_content &&
29 # delete the transient branch
30 git branch -D transient_branch &&
31 # pack the repo
32 git repack -A -d -l &&
33 # verify objects are packed in repository
34 test 3 = $(git verify-pack -v -- .git/objects/pack/*.idx |
87539416 35 egrep "^($fsha1|$csha1|$tsha1) " |
ccc12972
BC
36 sort | uniq | wc -l) &&
37 git show $fsha1 &&
38 git show $csha1 &&
39 git show $tsha1 &&
713c79e8
JH
40 # now expire the reflog, while keeping reachable ones but expiring
41 # unreachables immediately
42 test_tick &&
43 sometimeago=$(( $test_tick - 10000 )) &&
44 git reflog expire --expire=$sometimeago --expire-unreachable=$test_tick --all &&
ccc12972
BC
45 # and repack
46 git repack -A -d -l &&
47 # verify objects are retained unpacked
48 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
87539416 49 egrep "^($fsha1|$csha1|$tsha1) " |
ccc12972
BC
50 sort | uniq | wc -l) &&
51 git show $fsha1 &&
52 git show $csha1 &&
53 git show $tsha1
54'
55
e896912c
BC
56compare_mtimes ()
57{
decf711f
PSU
58 read tref &&
59 while read t; do
76e057db 60 test "$tref" = "$t" || return 1
d0409938 61 done
e896912c
BC
62}
63
83d0289d 64test_expect_success '-A without -d option leaves unreachable objects packed' '
e896912c
BC
65 fsha1path=$(echo "$fsha1" | sed -e "s|\(..\)|\1/|") &&
66 fsha1path=".git/objects/$fsha1path" &&
67 csha1path=$(echo "$csha1" | sed -e "s|\(..\)|\1/|") &&
68 csha1path=".git/objects/$csha1path" &&
69 tsha1path=$(echo "$tsha1" | sed -e "s|\(..\)|\1/|") &&
70 tsha1path=".git/objects/$tsha1path" &&
71 git branch transient_branch $csha1 &&
72 git repack -a -d -l &&
73 test ! -f "$fsha1path" &&
74 test ! -f "$csha1path" &&
75 test ! -f "$tsha1path" &&
76 test 1 = $(ls -1 .git/objects/pack/pack-*.pack | wc -l) &&
77 packfile=$(ls .git/objects/pack/pack-*.pack) &&
78 git branch -D transient_branch &&
713c79e8 79 test_tick &&
e896912c 80 git repack -A -l &&
83d0289d
BC
81 test ! -f "$fsha1path" &&
82 test ! -f "$csha1path" &&
83 test ! -f "$tsha1path" &&
84 git show $fsha1 &&
85 git show $csha1 &&
86 git show $tsha1
87'
88
89test_expect_success 'unpacked objects receive timestamp of pack file' '
90 tmppack=".git/objects/pack/tmp_pack" &&
91 ln "$packfile" "$tmppack" &&
92 git repack -A -l -d &&
deb9845a 93 test-tool chmtime --get "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
d0409938
JS
94 > mtimes &&
95 compare_mtimes < mtimes
e896912c
BC
96'
97
7e52f566
JK
98test_expect_success 'do not bother loosening old objects' '
99 obj1=$(echo one | git hash-object -w --stdin) &&
100 obj2=$(echo two | git hash-object -w --stdin) &&
101 pack1=$(echo $obj1 | git pack-objects .git/objects/pack/pack) &&
102 pack2=$(echo $obj2 | git pack-objects .git/objects/pack/pack) &&
103 git prune-packed &&
104 git cat-file -p $obj1 &&
105 git cat-file -p $obj2 &&
0e496492 106 test-tool chmtime =-86400 .git/objects/pack/pack-$pack2.pack &&
7e52f566
JK
107 git repack -A -d --unpack-unreachable=1.hour.ago &&
108 git cat-file -p $obj1 &&
109 test_must_fail git cat-file -p $obj2
110'
111
c90f9e13
JK
112test_expect_success 'keep packed objects found only in index' '
113 echo my-unique-content >file &&
114 git add file &&
115 git commit -m "make it reachable" &&
116 git gc &&
117 git reset HEAD^ &&
118 git reflog expire --expire=now --all &&
119 git add file &&
0e496492 120 test-tool chmtime =-86400 .git/objects/pack/* &&
c90f9e13
JK
121 git gc --prune=1.hour.ago &&
122 git cat-file blob :file
123'
124
905f27b8
JK
125test_expect_success 'repack -k keeps unreachable packed objects' '
126 # create packed-but-unreachable object
127 sha1=$(echo unreachable-packed | git hash-object -w --stdin) &&
128 pack=$(echo $sha1 | git pack-objects .git/objects/pack/pack) &&
129 git prune-packed &&
130
131 # -k should keep it
132 git repack -adk &&
133 git cat-file -p $sha1 &&
134
135 # and double check that without -k it would have been removed
136 git repack -ad &&
137 test_must_fail git cat-file -p $sha1
138'
139
e26a8c47
JK
140test_expect_success 'repack -k packs unreachable loose objects' '
141 # create loose unreachable object
142 sha1=$(echo would-be-deleted-loose | git hash-object -w --stdin) &&
143 objpath=.git/objects/$(echo $sha1 | sed "s,..,&/,") &&
144 test_path_is_file $objpath &&
145
146 # and confirm that the loose object goes away, but we can
147 # still access it (ergo, it is packed)
148 git repack -adk &&
149 test_path_is_missing $objpath &&
150 git cat-file -p $sha1
151'
152
ccc12972 153test_done