clone: use free() instead of UNLEAK()
[git.git] / t / t1409-avoid-packing-refs.sh
blobf23c0152a858265e4a8c6b0c068e00823aadb444
1 #!/bin/sh
3 test_description='avoid rewriting packed-refs unnecessarily'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 # Add an identifying mark to the packed-refs file header line. This
9 # shouldn't upset readers, and it should be omitted if the file is
10 # ever rewritten.
11 mark_packed_refs () {
12 sed -e "s/^\(#.*\)/\1 t1409 /" .git/packed-refs >.git/packed-refs.new &&
13 mv .git/packed-refs.new .git/packed-refs
16 # Verify that the packed-refs file is still marked.
17 check_packed_refs_marked () {
18 grep -q '^#.* t1409 ' .git/packed-refs
21 test_expect_success 'setup' '
22 git commit --allow-empty -m "Commit A" &&
23 A=$(git rev-parse HEAD) &&
24 git commit --allow-empty -m "Commit B" &&
25 B=$(git rev-parse HEAD) &&
26 git commit --allow-empty -m "Commit C" &&
27 C=$(git rev-parse HEAD)
30 test_expect_success 'do not create packed-refs file gratuitously' '
31 test_path_is_missing .git/packed-refs &&
32 git update-ref refs/heads/foo $A &&
33 test_path_is_missing .git/packed-refs &&
34 git update-ref refs/heads/foo $B &&
35 test_path_is_missing .git/packed-refs &&
36 git update-ref refs/heads/foo $C $B &&
37 test_path_is_missing .git/packed-refs &&
38 git update-ref -d refs/heads/foo &&
39 test_path_is_missing .git/packed-refs
42 test_expect_success 'check that marking the packed-refs file works' '
43 git for-each-ref >expected &&
44 git pack-refs --all &&
45 mark_packed_refs &&
46 check_packed_refs_marked &&
47 git for-each-ref >actual &&
48 test_cmp expected actual &&
49 git pack-refs --all &&
50 ! check_packed_refs_marked &&
51 git for-each-ref >actual2 &&
52 test_cmp expected actual2
55 test_expect_success 'leave packed-refs untouched on update of packed' '
56 git update-ref refs/heads/packed-update $A &&
57 git pack-refs --all &&
58 mark_packed_refs &&
59 git update-ref refs/heads/packed-update $B &&
60 check_packed_refs_marked
63 test_expect_success 'leave packed-refs untouched on checked update of packed' '
64 git update-ref refs/heads/packed-checked-update $A &&
65 git pack-refs --all &&
66 mark_packed_refs &&
67 git update-ref refs/heads/packed-checked-update $B $A &&
68 check_packed_refs_marked
71 test_expect_success 'leave packed-refs untouched on verify of packed' '
72 git update-ref refs/heads/packed-verify $A &&
73 git pack-refs --all &&
74 mark_packed_refs &&
75 echo "verify refs/heads/packed-verify $A" | git update-ref --stdin &&
76 check_packed_refs_marked
79 test_expect_success 'touch packed-refs on delete of packed' '
80 git update-ref refs/heads/packed-delete $A &&
81 git pack-refs --all &&
82 mark_packed_refs &&
83 git update-ref -d refs/heads/packed-delete &&
84 ! check_packed_refs_marked
87 test_expect_success 'leave packed-refs untouched on update of loose' '
88 git pack-refs --all &&
89 git update-ref refs/heads/loose-update $A &&
90 mark_packed_refs &&
91 git update-ref refs/heads/loose-update $B &&
92 check_packed_refs_marked
95 test_expect_success 'leave packed-refs untouched on checked update of loose' '
96 git pack-refs --all &&
97 git update-ref refs/heads/loose-checked-update $A &&
98 mark_packed_refs &&
99 git update-ref refs/heads/loose-checked-update $B $A &&
100 check_packed_refs_marked
103 test_expect_success 'leave packed-refs untouched on verify of loose' '
104 git pack-refs --all &&
105 git update-ref refs/heads/loose-verify $A &&
106 mark_packed_refs &&
107 echo "verify refs/heads/loose-verify $A" | git update-ref --stdin &&
108 check_packed_refs_marked
111 test_expect_success 'leave packed-refs untouched on delete of loose' '
112 git pack-refs --all &&
113 git update-ref refs/heads/loose-delete $A &&
114 mark_packed_refs &&
115 git update-ref -d refs/heads/loose-delete &&
116 check_packed_refs_marked
119 test_done