#!/bin/sh # # Copyright (c) 2005 Junio C Hamano # global test_description := ''git apply with rejects '' source ./test-lib.sh test_expect_success setup ' for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 do echo $i done >file1 && cat file1 >saved.file1 && git update-index --add file1 && git commit -m initial && for i in 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 do echo $i done >file1 && git diff >patch.1 && cat file1 >clean && for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 do echo $i done >expected && mv file1 file2 && git update-index --add --remove file1 file2 && git diff -M HEAD >patch.2 && rm -f file1 file2 && mv saved.file1 file1 && git update-index --add --remove file1 file2 && for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 do echo $i done >file1 && cat file1 >saved.file1 ' test_expect_success 'apply --reject is incompatible with --3way' ' test_when_finished "cat saved.file1 >file1" && git diff >patch.0 && git checkout file1 && test_must_fail git apply --reject --3way patch.0 && git diff --exit-code ' test_expect_success 'apply without --reject should fail' ' test_must_fail git apply patch.1 && test_cmp file1 saved.file1 ' test_expect_success 'apply without --reject should fail' ' test_must_fail git apply --verbose patch.1 && test_cmp file1 saved.file1 ' test_expect_success 'apply with --reject should fail but update the file' ' cat saved.file1 >file1 && rm -f file1.rej file2.rej && test_must_fail git apply --reject patch.1 && test_cmp file1 expected && cat file1.rej && test_path_is_missing file2.rej ' test_expect_success 'apply with --reject should fail but update the file' ' cat saved.file1 >file1 && rm -f file1.rej file2.rej file2 && test_must_fail git apply --reject patch.2 >rejects && test_path_is_missing file1 && test_cmp file2 expected && cat file2.rej && test_path_is_missing file1.rej ' test_expect_success 'the same test with --verbose' ' cat saved.file1 >file1 && rm -f file1.rej file2.rej file2 && test_must_fail git apply --reject --verbose patch.2 >rejects && test_path_is_missing file1 && test_cmp file2 expected && cat file2.rej && test_path_is_missing file1.rej ' test_expect_success 'apply cleanly with --verbose' ' git cat-file -p HEAD:file1 >file1 && rm -f file?.rej file2 && git apply --verbose patch.1 && test_cmp file1 clean ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git apply with rejects\n"> <"\n">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\tfor i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21\n"> <"\tdo\n"> <"\t\techo $i\n"> <"\tdone >file1 &&\n"> <"\tcat file1 >saved.file1 &&\n"> <"\tgit update-index --add file1 &&\n"> <"\tgit commit -m initial &&\n"> <"\n"> <"\tfor i in 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21\n"> <"\tdo\n"> <"\t\techo $i\n"> <"\tdone >file1 &&\n"> <"\tgit diff >patch.1 &&\n"> <"\tcat file1 >clean &&\n"> <"\n"> <"\tfor i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21\n"> <"\tdo\n"> <"\t\techo $i\n"> <"\tdone >expected &&\n"> <"\n"> <"\tmv file1 file2 &&\n"> <"\tgit update-index --add --remove file1 file2 &&\n"> <"\tgit diff -M HEAD >patch.2 &&\n"> <"\n"> <"\trm -f file1 file2 &&\n"> <"\tmv saved.file1 file1 &&\n"> <"\tgit update-index --add --remove file1 file2 &&\n"> <"\n"> <"\tfor i in 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21\n"> <"\tdo\n"> <"\t\techo $i\n"> <"\tdone >file1 &&\n"> <"\n"> <"\tcat file1 >saved.file1\n"> ) } ) (C {(test_expect_success)} {(SQ <"apply --reject is incompatible with --3way">)} { (SQ <"\n"> <"\ttest_when_finished \"cat saved.file1 >file1\" &&\n"> <"\tgit diff >patch.0 &&\n"> <"\tgit checkout file1 &&\n"> <"\ttest_must_fail git apply --reject --3way patch.0 &&\n"> <"\tgit diff --exit-code\n"> ) } ) (C {(test_expect_success)} {(SQ <"apply without --reject should fail">)} { (SQ <"\n"> <"\n"> <"\ttest_must_fail git apply patch.1 &&\n"> <"\ttest_cmp file1 saved.file1\n">) } ) (C {(test_expect_success)} {(SQ <"apply without --reject should fail">)} { (SQ <"\n"> <"\n"> <"\ttest_must_fail git apply --verbose patch.1 &&\n"> <"\ttest_cmp file1 saved.file1\n"> ) } ) (C {(test_expect_success)} {(SQ <"apply with --reject should fail but update the file">)} { (SQ <"\n"> <"\n"> <"\tcat saved.file1 >file1 &&\n"> <"\trm -f file1.rej file2.rej &&\n"> <"\n"> <"\ttest_must_fail git apply --reject patch.1 &&\n"> <"\ttest_cmp file1 expected &&\n"> <"\n"> <"\tcat file1.rej &&\n"> <"\ttest_path_is_missing file2.rej\n"> ) } ) (C {(test_expect_success)} {(SQ <"apply with --reject should fail but update the file">)} { (SQ <"\n"> <"\n"> <"\tcat saved.file1 >file1 &&\n"> <"\trm -f file1.rej file2.rej file2 &&\n"> <"\n"> <"\ttest_must_fail git apply --reject patch.2 >rejects &&\n"> <"\ttest_path_is_missing file1 &&\n"> <"\ttest_cmp file2 expected &&\n"> <"\n"> <"\tcat file2.rej &&\n"> <"\ttest_path_is_missing file1.rej\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"the same test with --verbose">)} { (SQ <"\n"> <"\n"> <"\tcat saved.file1 >file1 &&\n"> <"\trm -f file1.rej file2.rej file2 &&\n"> <"\n"> <"\ttest_must_fail git apply --reject --verbose patch.2 >rejects &&\n"> <"\ttest_path_is_missing file1 &&\n"> <"\ttest_cmp file2 expected &&\n"> <"\n"> <"\tcat file2.rej &&\n"> <"\ttest_path_is_missing file1.rej\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"apply cleanly with --verbose">)} { (SQ <"\n"> <"\n"> <"\tgit cat-file -p HEAD:file1 >file1 &&\n"> <"\trm -f file?.rej file2 &&\n"> <"\n"> <"\tgit apply --verbose patch.1 &&\n"> <"\n"> <"\ttest_cmp file1 clean\n"> ) } ) (C {(test_done)}) ] )