]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1409-avoid-packing-refs.sh
Merge branch 'ml/log-merge-with-cherry-pick-and-other-pseudo-heads'
[thirdparty/git.git] / t / t1409-avoid-packing-refs.sh
CommitLineData
cf79bd9f
MH
1#!/bin/sh
2
3test_description='avoid rewriting packed-refs unnecessarily'
4
03267e86 5TEST_PASSES_SANITIZE_LEAK=true
cf79bd9f
MH
6. ./test-lib.sh
7
bbd61069
PS
8if test_have_prereq !REFFILES
9then
10 skip_all='skipping files-backend specific pack-refs tests'
11 test_done
12fi
13
cf79bd9f
MH
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.
17mark_packed_refs () {
b87b02cf 18 sed -e "s/^\(#.*\)/\1 t1409 /" .git/packed-refs >.git/packed-refs.new &&
cf79bd9f
MH
19 mv .git/packed-refs.new .git/packed-refs
20}
21
22# Verify that the packed-refs file is still marked.
23check_packed_refs_marked () {
24 grep -q '^#.* t1409 ' .git/packed-refs
25}
26
27test_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)
34'
35
7c6bd25c 36test_expect_success 'do not create packed-refs file gratuitously' '
62d58cda 37 test_path_is_missing .git/packed-refs &&
cf79bd9f 38 git update-ref refs/heads/foo $A &&
62d58cda 39 test_path_is_missing .git/packed-refs &&
cf79bd9f 40 git update-ref refs/heads/foo $B &&
62d58cda 41 test_path_is_missing .git/packed-refs &&
cf79bd9f 42 git update-ref refs/heads/foo $C $B &&
62d58cda 43 test_path_is_missing .git/packed-refs &&
cf79bd9f 44 git update-ref -d refs/heads/foo &&
62d58cda 45 test_path_is_missing .git/packed-refs
cf79bd9f
MH
46'
47
48test_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 &&
f511bc02 56 ! check_packed_refs_marked &&
cf79bd9f
MH
57 git for-each-ref >actual2 &&
58 test_cmp expected actual2
59'
60
61test_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
67'
68
69test_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
75'
76
77test_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
83'
84
85test_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 &&
f511bc02 90 ! check_packed_refs_marked
cf79bd9f
MH
91'
92
93test_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
99'
100
101test_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
107'
108
109test_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
115'
116
7c6bd25c 117test_expect_success 'leave packed-refs untouched on delete of loose' '
cf79bd9f
MH
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
123'
124
125test_done