t1409: check that `packed-refs` is not rewritten unnecessarily

There is no need to rewrite the `packed-refs` file except for the case that we are deleting a reference that has a packed version. Verify that `packed-refs` is not rewritten when it shouldn't be. In fact, two of these tests fail: * A new (empty) `packed-refs` file is created when deleting any loose reference and no `packed-refs` file previously existed. * The `packed-refs` file is rewritten unnecessarily when deleting a loose reference that has no packed counterpart. Both problems will be fixed in the next commit. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Oct 25, 2017 at 11:53 UTC cf79bd9f4c34c635a5a7eeff2699a24744c5a129
1 file changed +118
t/t1409-avoid-packing-refs.sh new
+118
@@ -0,0 +1,118 @@
1 +#!/bin/sh
2 +
3 +test_description='avoid rewriting packed-refs unnecessarily'
4 +
5 +. ./test-lib.sh
6 +
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
13 +}
14 +
15 +# Verify that the packed-refs file is still marked.
16 +check_packed_refs_marked () {
17 + grep -q '^#.* t1409 ' .git/packed-refs
18 +}
19 +
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)
27 +'
28 +
29 +test_expect_failure '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
39 +'
40 +
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
52 +'
53 +
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
60 +'
61 +
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
68 +'
69 +
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
76 +'
77 +
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
84 +'
85 +
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
92 +'
93 +
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
100 +'
101 +
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
108 +'
109 +
110 +test_expect_failure '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
116 +'
117 +
118 +test_done