3 # Copyright (c) 2005 Amos Waterland
4 # Copyright (c) 2006 Christian Couder
7 test_description='git pack-refs should not change the branch semantic
9 This test runs git pack-refs and git show-ref and checks that the branch
10 semantic is still the same.
14 test_expect_success 'enable reflogs' '
15 git config core.logallrefupdates true
19 'prepare a trivial repository' \
21 git update-index --add A &&
22 git commit -m "Initial commit." &&
23 HEAD=$(git rev-parse --verify HEAD)'
28 'see if git show-ref works as expected' \
30 SHA1=`cat .git/refs/heads/a` &&
31 echo "$SHA1 refs/heads/a" >expect &&
32 git show-ref a >result &&
33 test_cmp expect result'
36 'see if a branch still exists when packed' \
38 git pack-refs --all &&
39 rm -f .git/refs/heads/b &&
40 echo "$SHA1 refs/heads/b" >expect &&
41 git show-ref b >result &&
42 test_cmp expect result'
44 test_expect_success 'git branch c/d should barf if branch c exists' '
46 git pack-refs --all &&
47 rm -f .git/refs/heads/c &&
48 test_must_fail git branch c/d
52 'see if a branch still exists after git pack-refs --prune' \
54 git pack-refs --all --prune &&
55 echo "$SHA1 refs/heads/e" >expect &&
56 git show-ref e >result &&
57 test_cmp expect result'
59 test_expect_success 'see if git pack-refs --prune remove ref files' '
61 git pack-refs --all --prune &&
62 ! test -f .git/refs/heads/f
65 test_expect_success 'see if git pack-refs --prune removes empty dirs' '
67 git pack-refs --all --prune &&
68 ! test -e .git/refs/heads/r
72 'git branch g should work when git branch g/h has been deleted' \
74 git pack-refs --all --prune &&
77 git pack-refs --all &&
80 test_expect_success 'git branch i/j/k should barf if branch i exists' '
82 git pack-refs --all --prune &&
83 test_must_fail git branch i/j/k
87 'test git branch k after branch k/l/m and k/lm have been deleted' \
92 git branch -d k/l/m &&
97 'test git branch n after some branch deletion and pruning' \
102 git branch -d n/op &&
103 git pack-refs --all --prune &&
104 git branch -d n/o/p &&
107 test_expect_success \
108 'see if up-to-date packed refs are preserved' \
110 git pack-refs --all --prune &&
111 git update-ref refs/heads/q refs/heads/q &&
112 ! test -f .git/refs/heads/q'
114 test_expect_success 'pack, prune and repack' '
116 git pack-refs --all --prune &&
117 git show-ref >all-of-them &&
119 git show-ref >again &&
120 test_cmp all-of-them again
123 test_expect_success 'explicit pack-refs with dangling packed reference' '
124 git commit --allow-empty -m "soon to be garbage-collected" &&
125 git pack-refs --all &&
126 git reset --hard HEAD^ &&
127 git reflog expire --expire=all --all &&
128 git prune --expire=all &&
129 git pack-refs --all 2>result &&
130 test_cmp /dev/null result
133 test_expect_success 'delete ref with dangling packed version' '
134 git checkout -b lamb &&
135 git commit --allow-empty -m "future garbage" &&
136 git pack-refs --all &&
137 git reset --hard HEAD^ &&
138 git checkout master &&
139 git reflog expire --expire=all --all &&
140 git prune --expire=all &&
141 git branch -d lamb 2>result &&
142 test_cmp /dev/null result
145 test_expect_success 'delete ref while another dangling packed ref' '
147 git commit --allow-empty -m "future garbage" &&
148 git pack-refs --all &&
149 git reset --hard HEAD^ &&
150 git reflog expire --expire=all --all &&
151 git prune --expire=all &&
152 git branch -d lamb 2>result &&
153 test_cmp /dev/null result
156 test_expect_success 'pack ref directly below refs/' '
157 git update-ref refs/top HEAD &&
158 git pack-refs --all --prune &&
159 grep refs/top .git/packed-refs &&
160 test_path_is_missing .git/refs/top
163 test_expect_success 'disable reflogs' '
164 git config core.logallrefupdates false &&
168 test_expect_success 'create packed foo/bar/baz branch' '
169 git branch foo/bar/baz &&
170 git pack-refs --all --prune &&
171 test_path_is_missing .git/refs/heads/foo/bar/baz &&
172 test_path_is_missing .git/logs/refs/heads/foo/bar/baz
175 test_expect_success 'notice d/f conflict with existing directory' '
176 test_must_fail git branch foo &&
177 test_must_fail git branch foo/bar
180 test_expect_success 'existing directory reports concrete ref' '
181 test_must_fail git branch foo 2>stderr &&
182 grep refs/heads/foo/bar/baz stderr
185 test_expect_success 'notice d/f conflict with existing ref' '
186 test_must_fail git branch foo/bar/baz/extra &&
187 test_must_fail git branch foo/bar/baz/lots/of/extra/components
190 test_expect_success 'timeout if packed-refs.lock exists' '
191 LOCK=.git/packed-refs.lock &&
193 test_when_finished "rm -f $LOCK" &&
194 test_must_fail git pack-refs --all --prune
197 test_expect_success 'retry acquiring packed-refs.lock' '
198 LOCK=.git/packed-refs.lock &&
200 test_when_finished "wait; rm -f $LOCK" &&
202 ( sleep 1 ; rm -f $LOCK ) &
204 git -c core.packedrefstimeout=3000 pack-refs --all --prune