Add a few more values for receive.denyCurrentBranch
[git/dscho.git] / t / t7701-repack-unpack-unreachable.sh
blob200ab61278643e8b9deb4f624a95378e7e4c5b67
1 #!/bin/sh
3 test_description='git repack works correctly'
5 . ./test-lib.sh
7 fsha1=
8 csha1=
9 tsha1=
11 test_expect_success '-A with -d option leaves unreachable objects unpacked' '
12 echo content > file1 &&
13 git add . &&
14 test_tick &&
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) &&
21 test_tick &&
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 &&
27 test_tick &&
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 |
35 egrep "^($fsha1|$csha1|$tsha1) " |
36 sort | uniq | wc -l) &&
37 git show $fsha1 &&
38 git show $csha1 &&
39 git show $tsha1 &&
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 &&
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 |
49 egrep "^($fsha1|$csha1|$tsha1) " |
50 sort | uniq | wc -l) &&
51 git show $fsha1 &&
52 git show $csha1 &&
53 git show $tsha1
56 compare_mtimes ()
58 read tref rest &&
59 while read t rest; do
60 test "$tref" = "$t" || break
61 done
64 test_expect_success '-A without -d option leaves unreachable objects packed' '
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 &&
79 test_tick &&
80 git repack -A -l &&
81 test ! -f "$fsha1path" &&
82 test ! -f "$csha1path" &&
83 test ! -f "$tsha1path" &&
84 git show $fsha1 &&
85 git show $csha1 &&
86 git show $tsha1
89 test_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 &&
93 test-chmtime -v +0 "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
94 > mtimes &&
95 compare_mtimes < mtimes
98 test_done