#!/bin/sh global test_description := ''git am with corrupt input'' source ./test-lib.sh test_expect_success setup ' # Note the missing "+++" line: cat >bad-patch.diff <<-\EOF && From: A U Thor diff --git a/f b/f index 7898192..6178079 100644 --- a/f @@ -1 +1 @@ -a +b EOF echo a >f && git add f && test_tick && git commit -m initial ' # This used to fail before, too, but with a different diagnostic. # fatal: unable to write file '(null)' mode 100644: Bad address # Also, it had the unwanted side-effect of deleting f. test_expect_success 'try to apply corrupted patch' ' test_must_fail git am bad-patch.diff 2>actual ' test_expect_success 'compare diagnostic; ensure file is still here' ' echo "error: git diff header lacks filename information (line 4)" >expected && test_path_is_file f && test_i18ncmp expected actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git am with corrupt input">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\t# Note the missing \"+++\" line:\n"> <"\tcat >bad-patch.diff <<-\\EOF &&\n"> <"\tFrom: A U Thor \n"> <"\tdiff --git a/f b/f\n"> <"\tindex 7898192..6178079 100644\n"> <"\t--- a/f\n"> <"\t@@ -1 +1 @@\n"> <"\t-a\n"> <"\t+b\n"> <"\tEOF\n"> <"\n"> <"\techo a >f &&\n"> <"\tgit add f &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m initial\n"> ) } ) (C {(test_expect_success)} {(SQ <"try to apply corrupted patch">)} {(SQ <"\n"> <"\ttest_must_fail git am bad-patch.diff 2>actual\n">)} ) (C {(test_expect_success)} {(SQ <"compare diagnostic; ensure file is still here">)} { (SQ <"\n"> <"\techo \"error: git diff header lacks filename information (line 4)\" >expected &&\n"> <"\ttest_path_is_file f &&\n"> <"\ttest_i18ncmp expected actual\n"> ) } ) (C {(test_done)}) ] )