Skip to content

Commit d2992c6

Browse files
committed
Merge branch 'ab/pre-auto-gc-hook-test'
Test fix. * ab/pre-auto-gc-hook-test: gc tests: add a test for the "pre-auto-gc" hook
2 parents 308528a + 9eb542f commit d2992c6

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

t/t6500-gc.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,52 @@ test_expect_success 'gc --keep-largest-pack' '
9595
)
9696
'
9797

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+
98144
test_expect_success 'auto gc with too many loose objects does not attempt to create bitmaps' '
99145
test_config gc.auto 3 &&
100146
test_config gc.autodetach false &&

0 commit comments

Comments
 (0)