2006-08-17 00:55:29 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
2007-07-03 05:52:14 +00:00
|
|
|
test_description='git apply with rejects
|
2006-08-17 00:55:29 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2024-04-22 22:54:05 +00:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2006-08-17 00:55:29 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 >file1 &&
|
2006-08-17 00:55:29 +00:00
|
|
|
cat file1 >saved.file1 &&
|
|
|
|
git update-index --add file1 &&
|
|
|
|
git commit -m initial &&
|
|
|
|
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 >file1 &&
|
2006-08-17 00:55:29 +00:00
|
|
|
git diff >patch.1 &&
|
2006-08-18 10:10:19 +00:00
|
|
|
cat file1 >clean &&
|
|
|
|
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 >expected &&
|
2006-08-17 00:55:29 +00:00
|
|
|
|
|
|
|
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 &&
|
|
|
|
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 >file1 &&
|
2006-08-17 00:55:29 +00:00
|
|
|
|
|
|
|
cat file1 >saved.file1
|
|
|
|
'
|
|
|
|
|
2012-05-08 20:21:53 +00:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2006-08-17 00:55:29 +00:00
|
|
|
test_expect_success 'apply without --reject should fail' '
|
|
|
|
|
2015-03-20 10:13:18 +00:00
|
|
|
test_must_fail git apply patch.1 &&
|
2008-05-24 05:28:56 +00:00
|
|
|
test_cmp file1 saved.file1
|
2006-08-17 00:55:29 +00:00
|
|
|
'
|
|
|
|
|
2006-08-18 10:14:48 +00:00
|
|
|
test_expect_success 'apply without --reject should fail' '
|
|
|
|
|
2015-03-20 10:13:18 +00:00
|
|
|
test_must_fail git apply --verbose patch.1 &&
|
2008-05-24 05:28:56 +00:00
|
|
|
test_cmp file1 saved.file1
|
2006-08-18 10:14:48 +00:00
|
|
|
'
|
|
|
|
|
2006-08-17 00:55:29 +00:00
|
|
|
test_expect_success 'apply with --reject should fail but update the file' '
|
|
|
|
|
2006-08-18 10:10:19 +00:00
|
|
|
cat saved.file1 >file1 &&
|
|
|
|
rm -f file1.rej file2.rej &&
|
2006-08-17 00:55:29 +00:00
|
|
|
|
2015-03-20 10:13:18 +00:00
|
|
|
test_must_fail git apply --reject patch.1 &&
|
2018-10-05 21:54:04 +00:00
|
|
|
test_cmp expected file1 &&
|
2006-08-18 10:10:19 +00:00
|
|
|
|
2020-02-23 08:48:34 +00:00
|
|
|
test_path_is_file file1.rej &&
|
2015-03-20 10:13:18 +00:00
|
|
|
test_path_is_missing file2.rej
|
2006-08-17 00:55:29 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply with --reject should fail but update the file' '
|
|
|
|
|
2006-08-18 10:10:19 +00:00
|
|
|
cat saved.file1 >file1 &&
|
|
|
|
rm -f file1.rej file2.rej file2 &&
|
2006-08-17 00:55:29 +00:00
|
|
|
|
2015-03-20 10:13:18 +00:00
|
|
|
test_must_fail git apply --reject patch.2 >rejects &&
|
|
|
|
test_path_is_missing file1 &&
|
2018-10-05 21:54:04 +00:00
|
|
|
test_cmp expected file2 &&
|
2006-08-18 10:10:19 +00:00
|
|
|
|
2020-02-23 08:48:34 +00:00
|
|
|
test_path_is_file file2.rej &&
|
2015-03-20 10:13:18 +00:00
|
|
|
test_path_is_missing file1.rej
|
2006-08-18 10:10:19 +00:00
|
|
|
|
2006-08-17 00:55:29 +00:00
|
|
|
'
|
|
|
|
|
2006-08-18 10:14:48 +00:00
|
|
|
test_expect_success 'the same test with --verbose' '
|
|
|
|
|
|
|
|
cat saved.file1 >file1 &&
|
|
|
|
rm -f file1.rej file2.rej file2 &&
|
|
|
|
|
2015-03-20 10:13:18 +00:00
|
|
|
test_must_fail git apply --reject --verbose patch.2 >rejects &&
|
|
|
|
test_path_is_missing file1 &&
|
2018-10-05 21:54:04 +00:00
|
|
|
test_cmp expected file2 &&
|
2006-08-18 10:14:48 +00:00
|
|
|
|
2020-02-23 08:48:34 +00:00
|
|
|
test_path_is_file file2.rej &&
|
2015-03-20 10:13:18 +00:00
|
|
|
test_path_is_missing file1.rej
|
2006-08-18 10:14:48 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply cleanly with --verbose' '
|
|
|
|
|
|
|
|
git cat-file -p HEAD:file1 >file1 &&
|
|
|
|
rm -f file?.rej file2 &&
|
|
|
|
|
|
|
|
git apply --verbose patch.1 &&
|
|
|
|
|
2008-05-24 05:28:56 +00:00
|
|
|
test_cmp file1 clean
|
2006-08-18 10:14:48 +00:00
|
|
|
'
|
|
|
|
|
2006-08-17 00:55:29 +00:00
|
|
|
test_done
|