Merge branch 'cp/git-flush-is-an-env-bool'
[alt-git.git] / t / t1409-avoid-packing-refs.sh
blob7748973733e6adab07117192accabf7698189681
1 #!/bin/sh
3 test_description='avoid rewriting packed-refs unnecessarily'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 if test_have_prereq !REFFILES
9 then
10 skip_all='skipping files-backend specific pack-refs tests'
11 test_done
14 # Add an identifying mark to the packed-refs file header line. This
15 # shouldn't upset readers, and it should be omitted if the file is
16 # ever rewritten.
17 mark_packed_refs () {
18 sed -e "s/^\(#.*\)/\1 t1409 /" .git/packed-refs >.git/packed-refs.new &&
19 mv .git/packed-refs.new .git/packed-refs
22 # Verify that the packed-refs file is still marked.
23 check_packed_refs_marked () {
24 grep -q '^#.* t1409 ' .git/packed-refs
27 test_expect_success 'setup' '
28 git commit --allow-empty -m "Commit A" &&
29 A=$(git rev-parse HEAD) &&
30 git commit --allow-empty -m "Commit B" &&
31 B=$(git rev-parse HEAD) &&
32 git commit --allow-empty -m "Commit C" &&
33 C=$(git rev-parse HEAD)
36 test_expect_success 'do not create packed-refs file gratuitously' '
37 test_path_is_missing .git/packed-refs &&
38 git update-ref refs/heads/foo $A &&
39 test_path_is_missing .git/packed-refs &&
40 git update-ref refs/heads/foo $B &&
41 test_path_is_missing .git/packed-refs &&
42 git update-ref refs/heads/foo $C $B &&
43 test_path_is_missing .git/packed-refs &&
44 git update-ref -d refs/heads/foo &&
45 test_path_is_missing .git/packed-refs
48 test_expect_success 'check that marking the packed-refs file works' '
49 git for-each-ref >expected &&
50 git pack-refs --all &&
51 mark_packed_refs &&
52 check_packed_refs_marked &&
53 git for-each-ref >actual &&
54 test_cmp expected actual &&
55 git pack-refs --all &&
56 ! check_packed_refs_marked &&
57 git for-each-ref >actual2 &&
58 test_cmp expected actual2
61 test_expect_success 'leave packed-refs untouched on update of packed' '
62 git update-ref refs/heads/packed-update $A &&
63 git pack-refs --all &&
64 mark_packed_refs &&
65 git update-ref refs/heads/packed-update $B &&
66 check_packed_refs_marked
69 test_expect_success 'leave packed-refs untouched on checked update of packed' '
70 git update-ref refs/heads/packed-checked-update $A &&
71 git pack-refs --all &&
72 mark_packed_refs &&
73 git update-ref refs/heads/packed-checked-update $B $A &&
74 check_packed_refs_marked
77 test_expect_success 'leave packed-refs untouched on verify of packed' '
78 git update-ref refs/heads/packed-verify $A &&
79 git pack-refs --all &&
80 mark_packed_refs &&
81 echo "verify refs/heads/packed-verify $A" | git update-ref --stdin &&
82 check_packed_refs_marked
85 test_expect_success 'touch packed-refs on delete of packed' '
86 git update-ref refs/heads/packed-delete $A &&
87 git pack-refs --all &&
88 mark_packed_refs &&
89 git update-ref -d refs/heads/packed-delete &&
90 ! check_packed_refs_marked
93 test_expect_success 'leave packed-refs untouched on update of loose' '
94 git pack-refs --all &&
95 git update-ref refs/heads/loose-update $A &&
96 mark_packed_refs &&
97 git update-ref refs/heads/loose-update $B &&
98 check_packed_refs_marked
101 test_expect_success 'leave packed-refs untouched on checked update of loose' '
102 git pack-refs --all &&
103 git update-ref refs/heads/loose-checked-update $A &&
104 mark_packed_refs &&
105 git update-ref refs/heads/loose-checked-update $B $A &&
106 check_packed_refs_marked
109 test_expect_success 'leave packed-refs untouched on verify of loose' '
110 git pack-refs --all &&
111 git update-ref refs/heads/loose-verify $A &&
112 mark_packed_refs &&
113 echo "verify refs/heads/loose-verify $A" | git update-ref --stdin &&
114 check_packed_refs_marked
117 test_expect_success 'leave packed-refs untouched on delete of loose' '
118 git pack-refs --all &&
119 git update-ref refs/heads/loose-delete $A &&
120 mark_packed_refs &&
121 git update-ref -d refs/heads/loose-delete &&
122 check_packed_refs_marked
125 test_done