t/helper: merge test-write-cache into test-tool
[git.git] / t / t1409-avoid-packing-refs.sh
blobe5cb8a252dd1a7d8e65eece2fe4ee5e21d748b90
1 #!/bin/sh
3 test_description='avoid rewriting packed-refs unnecessarily'
5 . ./test-lib.sh
7 # Add an identifying mark to the packed-refs file header line. This
8 # shouldn't upset readers, and it should be omitted if the file is
9 # ever rewritten.
10 mark_packed_refs () {
11 sed -e "s/^\(#.*\)/\1 t1409 /" <.git/packed-refs >.git/packed-refs.new &&
12 mv .git/packed-refs.new .git/packed-refs
15 # Verify that the packed-refs file is still marked.
16 check_packed_refs_marked () {
17 grep -q '^#.* t1409 ' .git/packed-refs
20 test_expect_success 'setup' '
21 git commit --allow-empty -m "Commit A" &&
22 A=$(git rev-parse HEAD) &&
23 git commit --allow-empty -m "Commit B" &&
24 B=$(git rev-parse HEAD) &&
25 git commit --allow-empty -m "Commit C" &&
26 C=$(git rev-parse HEAD)
29 test_expect_success 'do not create packed-refs file gratuitously' '
30 test_must_fail test -f .git/packed-refs &&
31 git update-ref refs/heads/foo $A &&
32 test_must_fail test -f .git/packed-refs &&
33 git update-ref refs/heads/foo $B &&
34 test_must_fail test -f .git/packed-refs &&
35 git update-ref refs/heads/foo $C $B &&
36 test_must_fail test -f .git/packed-refs &&
37 git update-ref -d refs/heads/foo &&
38 test_must_fail test -f .git/packed-refs
41 test_expect_success 'check that marking the packed-refs file works' '
42 git for-each-ref >expected &&
43 git pack-refs --all &&
44 mark_packed_refs &&
45 check_packed_refs_marked &&
46 git for-each-ref >actual &&
47 test_cmp expected actual &&
48 git pack-refs --all &&
49 test_must_fail check_packed_refs_marked &&
50 git for-each-ref >actual2 &&
51 test_cmp expected actual2
54 test_expect_success 'leave packed-refs untouched on update of packed' '
55 git update-ref refs/heads/packed-update $A &&
56 git pack-refs --all &&
57 mark_packed_refs &&
58 git update-ref refs/heads/packed-update $B &&
59 check_packed_refs_marked
62 test_expect_success 'leave packed-refs untouched on checked update of packed' '
63 git update-ref refs/heads/packed-checked-update $A &&
64 git pack-refs --all &&
65 mark_packed_refs &&
66 git update-ref refs/heads/packed-checked-update $B $A &&
67 check_packed_refs_marked
70 test_expect_success 'leave packed-refs untouched on verify of packed' '
71 git update-ref refs/heads/packed-verify $A &&
72 git pack-refs --all &&
73 mark_packed_refs &&
74 echo "verify refs/heads/packed-verify $A" | git update-ref --stdin &&
75 check_packed_refs_marked
78 test_expect_success 'touch packed-refs on delete of packed' '
79 git update-ref refs/heads/packed-delete $A &&
80 git pack-refs --all &&
81 mark_packed_refs &&
82 git update-ref -d refs/heads/packed-delete &&
83 test_must_fail check_packed_refs_marked
86 test_expect_success 'leave packed-refs untouched on update of loose' '
87 git pack-refs --all &&
88 git update-ref refs/heads/loose-update $A &&
89 mark_packed_refs &&
90 git update-ref refs/heads/loose-update $B &&
91 check_packed_refs_marked
94 test_expect_success 'leave packed-refs untouched on checked update of loose' '
95 git pack-refs --all &&
96 git update-ref refs/heads/loose-checked-update $A &&
97 mark_packed_refs &&
98 git update-ref refs/heads/loose-checked-update $B $A &&
99 check_packed_refs_marked
102 test_expect_success 'leave packed-refs untouched on verify of loose' '
103 git pack-refs --all &&
104 git update-ref refs/heads/loose-verify $A &&
105 mark_packed_refs &&
106 echo "verify refs/heads/loose-verify $A" | git update-ref --stdin &&
107 check_packed_refs_marked
110 test_expect_success 'leave packed-refs untouched on delete of loose' '
111 git pack-refs --all &&
112 git update-ref refs/heads/loose-delete $A &&
113 mark_packed_refs &&
114 git update-ref -d refs/heads/loose-delete &&
115 check_packed_refs_marked
118 test_done