gc tests: add a test for the "pre-auto-gc" hook

Add a missing test for the behavior of the pre-auto-gc hook added in 0b85d92661e (Documentation/hooks: add pre-auto-gc hook, 2008-04-02). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 14, 2021 at 12:39 UTC 9eb542f2eea88234d1ae8f84f40ef0f8daf1e87e
1 file changed +46
t/t6500-gc.sh
+46
@@ -95,6 +95,52 @@ test_expect_success 'gc --keep-largest-pack' '
95 )
96 '
97
98 +test_expect_success 'pre-auto-gc hook can stop auto gc' '
99 + cat >err.expect <<-\EOF &&
100 + no gc for you
101 + EOF
102 +
103 + git init pre-auto-gc-hook &&
104 + (
105 + cd pre-auto-gc-hook &&
106 + write_script ".git/hooks/pre-auto-gc" <<-\EOF &&
107 + echo >&2 no gc for you &&
108 + exit 1
109 + EOF
110 +
111 + git config gc.auto 3 &&
112 + git config gc.autoDetach false &&
113 +
114 + # We need to create two object whose sha1s start with 17
115 + # since this is what git gc counts. As it happens, these
116 + # two blobs will do so.
117 + test_commit "$(test_oid obj1)" &&
118 + test_commit "$(test_oid obj2)" &&
119 +
120 + git gc --auto >../out.actual 2>../err.actual
121 + ) &&
122 + test_must_be_empty out.actual &&
123 + test_cmp err.expect err.actual &&
124 +
125 + cat >err.expect <<-\EOF &&
126 + will gc for you
127 + Auto packing the repository for optimum performance.
128 + See "git help gc" for manual housekeeping.
129 + EOF
130 +
131 + (
132 + cd pre-auto-gc-hook &&
133 + write_script ".git/hooks/pre-auto-gc" <<-\EOF &&
134 + echo >&2 will gc for you &&
135 + exit 0
136 + EOF
137 + git gc --auto >../out.actual 2>../err.actual
138 + ) &&
139 +
140 + test_must_be_empty out.actual &&
141 + test_cmp err.expect err.actual
142 +'
143 +
144 test_expect_success 'auto gc with too many loose objects does not attempt to create bitmaps' '
145 test_config gc.auto 3 &&
146 test_config gc.autodetach false &&