Skip to content

Commit 02a1a42

Browse files
mhaggergitster
authored andcommitted
t3210: add some tests of bogus packed-refs file contents
If `packed-refs` contains indecipherable lines, we should emit an error and quit rather than just skipping the lines. Unfortunately, we currently do the latter. Add some failing tests demonstrating the problem. This 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>
1 parent e5cc7d7 commit 02a1a42

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

t/t3210-pack-refs.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,33 @@ test_expect_success 'notice d/f conflict with existing ref' '
194194
test_must_fail git branch foo/bar/baz/lots/of/extra/components
195195
'
196196

197+
test_expect_failure 'reject packed-refs with unterminated line' '
198+
cp .git/packed-refs .git/packed-refs.bak &&
199+
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
200+
printf "%s" "$HEAD refs/zzzzz" >>.git/packed-refs &&
201+
echo "fatal: unterminated line in .git/packed-refs: $HEAD refs/zzzzz" >expected_err &&
202+
test_must_fail git for-each-ref >out 2>err &&
203+
test_cmp expected_err err
204+
'
205+
206+
test_expect_failure 'reject packed-refs containing junk' '
207+
cp .git/packed-refs .git/packed-refs.bak &&
208+
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
209+
printf "%s\n" "bogus content" >>.git/packed-refs &&
210+
echo "fatal: unexpected line in .git/packed-refs: bogus content" >expected_err &&
211+
test_must_fail git for-each-ref >out 2>err &&
212+
test_cmp expected_err err
213+
'
214+
215+
test_expect_failure 'reject packed-refs with a short SHA-1' '
216+
cp .git/packed-refs .git/packed-refs.bak &&
217+
test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
218+
printf "%.7s %s\n" $HEAD refs/zzzzz >>.git/packed-refs &&
219+
printf "fatal: unexpected line in .git/packed-refs: %.7s %s\n" $HEAD refs/zzzzz >expected_err &&
220+
test_must_fail git for-each-ref >out 2>err &&
221+
test_cmp expected_err err
222+
'
223+
197224
test_expect_success 'timeout if packed-refs.lock exists' '
198225
LOCK=.git/packed-refs.lock &&
199226
>"$LOCK" &&

0 commit comments

Comments
 (0)