3 test_description='git repack works correctly'
11 test_expect_success '-A with -d option leaves unreachable objects unpacked' '
12 echo content > file1 &&
14 git commit -m initial_commit &&
15 # create a transient branch with unique content
16 git checkout -b transient_branch &&
17 echo more content >> file1 &&
18 # record the objects created in the database for file, commit, tree
19 fsha1=$(git hash-object file1) &&
20 git commit -a -m more_content &&
21 csha1=$(git rev-parse HEAD^{commit}) &&
22 tsha1=$(git rev-parse HEAD^{tree}) &&
23 git checkout master &&
24 echo even more content >> file1 &&
25 git commit -a -m even_more_content &&
26 # delete the transient branch
27 git branch -D transient_branch &&
29 git repack -A -d -l &&
30 # verify objects are packed in repository
31 test 3 = $(git verify-pack -v -- .git/objects/pack/*.idx |
32 egrep "^($fsha1|$csha1|$tsha1) " |
33 sort | uniq | wc -l) &&
37 # now expire the reflog
39 git reflog expire --expire-unreachable=now --all &&
41 git repack -A -d -l &&
42 # verify objects are retained unpacked
43 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
44 egrep "^($fsha1|$csha1|$tsha1) " |
45 sort | uniq | wc -l) &&
55 test "$tref" = "$t" || break
59 test_expect_success '-A without -d option leaves unreachable objects packed' '
60 fsha1path=$(echo "$fsha1" | sed -e "s|\(..\)|\1/|") &&
61 fsha1path=".git/objects/$fsha1path" &&
62 csha1path=$(echo "$csha1" | sed -e "s|\(..\)|\1/|") &&
63 csha1path=".git/objects/$csha1path" &&
64 tsha1path=$(echo "$tsha1" | sed -e "s|\(..\)|\1/|") &&
65 tsha1path=".git/objects/$tsha1path" &&
66 git branch transient_branch $csha1 &&
67 git repack -a -d -l &&
68 test ! -f "$fsha1path" &&
69 test ! -f "$csha1path" &&
70 test ! -f "$tsha1path" &&
71 test 1 = $(ls -1 .git/objects/pack/pack-*.pack | wc -l) &&
72 packfile=$(ls .git/objects/pack/pack-*.pack) &&
73 git branch -D transient_branch &&
76 test ! -f "$fsha1path" &&
77 test ! -f "$csha1path" &&
78 test ! -f "$tsha1path" &&
84 test_expect_success 'unpacked objects receive timestamp of pack file' '
85 tmppack=".git/objects/pack/tmp_pack" &&
86 ln "$packfile" "$tmppack" &&
87 git repack -A -l -d &&
88 test-chmtime -v +0 "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
90 compare_mtimes < mtimes