1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
6 test_description='git-apply with rejects
8 '
10 . ./test-lib.sh
12 test_expect_success setup '
13 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
14 do
15 echo $i
16 done >file1 &&
17 cat file1 >saved.file1 &&
18 git update-index --add file1 &&
19 git commit -m initial &&
21 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
22 do
23 echo $i
24 done >file1 &&
25 git diff >patch.1 &&
27 mv file1 file2 &&
28 git update-index --add --remove file1 file2 &&
29 git diff -M HEAD >patch.2 &&
31 rm -f file1 file2 &&
32 mv saved.file1 file1 &&
33 git update-index --add --remove file1 file2 &&
35 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
36 do
37 echo $i
38 done >file1 &&
40 cat file1 >saved.file1
41 '
43 test_expect_success 'apply without --reject should fail' '
45 if git apply patch.1
46 then
47 echo "Eh? Why?"
48 exit 1
49 fi
51 diff -u file1 saved.file1
52 '
54 test_expect_success 'apply with --reject should fail but update the file' '
56 cat saved.file1 >file1
58 if git apply --reject patch.1 >rejects
59 then
60 echo "succeeds with --reject?"
61 exit 1
62 fi
63 cat rejects
64 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
65 do
66 echo $i
67 done >expected.file1 &&
69 diff -u file1 expected.file1
70 '
72 test_expect_success 'apply with --reject should fail but update the file' '
74 cat saved.file1 >file1
76 if git apply --reject patch.2 >rejects
77 then
78 echo "succeeds with --reject?"
79 exit 1
80 fi
82 cat rejects
84 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
85 do
86 echo $i
87 done >expected.file2 &&
89 test -f file1 && {
90 echo "file1 still exists?"
91 exit 1
92 }
93 diff -u file2 expected.file2
94 '
96 test_done