3362819c3a21a731d2fe0b53128cb2cb1d51ea90
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='git-apply with rejects
7
8'
9
10. ./test-lib.sh
11
12test_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 &&
20
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 &&
26
27 mv file1 file2 &&
28 git update-index --add --remove file1 file2 &&
29 git diff -M HEAD >patch.2 &&
30
31 rm -f file1 file2 &&
32 mv saved.file1 file1 &&
33 git update-index --add --remove file1 file2 &&
34
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 &&
39
40 cat file1 >saved.file1
41'
42
43test_expect_success 'apply without --reject should fail' '
44
45 if git apply patch.1
46 then
47 echo "Eh? Why?"
48 exit 1
49 fi
50
51 diff -u file1 saved.file1
52'
53
54test_expect_success 'apply with --reject should fail but update the file' '
55
56 cat saved.file1 >file1
57
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 &&
68
69 diff -u file1 expected.file1
70'
71
72test_expect_success 'apply with --reject should fail but update the file' '
73
74 cat saved.file1 >file1
75
76 if git apply --reject patch.2 >rejects
77 then
78 echo "succeeds with --reject?"
79 exit 1
80 fi
81
82 cat rejects
83
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 &&
88
89 test -f file1 && {
90 echo "file1 still exists?"
91 exit 1
92 }
93 diff -u file2 expected.file2
94'
95
96test_done