Merge branch 'sr/local-config'
[git/jnareb-git/bp-gitweb.git] / t / t4132-apply-removal.sh
blobbb1ffe3b6cfe491137b34993fe2e3bed99908dff
1 #!/bin/sh
3 # Copyright (c) 2009 Junio C Hamano
5 test_description='git-apply notices removal patches generated by GNU diff'
7 . ./test-lib.sh
9 test_expect_success setup '
10 cat <<-EOF >c &&
11 diff -ruN a/file b/file
12 --- a/file TS0
13 +++ b/file TS1
14 @@ -0,0 +1 @@
15 +something
16 EOF
18 cat <<-EOF >d &&
19 diff -ruN a/file b/file
20 --- a/file TS0
21 +++ b/file TS1
22 @@ -1 +0,0 @@
23 -something
24 EOF
26 timeWest="1982-09-16 07:00:00.000000000 -0800" &&
27 timeGMT="1982-09-16 15:00:00.000000000 +0000" &&
28 timeEast="1982-09-17 00:00:00.000000000 +0900" &&
30 epocWest="1969-12-31 16:00:00.000000000 -0800" &&
31 epocGMT="1970-01-01 00:00:00.000000000 +0000" &&
32 epocEast="1970-01-01 09:00:00.000000000 +0900" &&
34 sed -e "s/TS0/$epocWest/" -e "s/TS1/$timeWest/" <c >createWest.patch &&
35 sed -e "s/TS0/$epocEast/" -e "s/TS1/$timeEast/" <c >createEast.patch &&
36 sed -e "s/TS0/$epocGMT/" -e "s/TS1/$timeGMT/" <c >createGMT.patch &&
38 sed -e "s/TS0/$timeWest/" -e "s/TS1/$timeWest/" <c >addWest.patch &&
39 sed -e "s/TS0/$timeEast/" -e "s/TS1/$timeEast/" <c >addEast.patch &&
40 sed -e "s/TS0/$timeGMT/" -e "s/TS1/$timeGMT/" <c >addGMT.patch &&
42 sed -e "s/TS0/$timeWest/" -e "s/TS1/$timeWest/" <d >emptyWest.patch &&
43 sed -e "s/TS0/$timeEast/" -e "s/TS1/$timeEast/" <d >emptyEast.patch &&
44 sed -e "s/TS0/$timeGMT/" -e "s/TS1/$timeGMT/" <d >emptyGMT.patch &&
46 sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest/" <d >removeWest.patch &&
47 sed -e "s/TS0/$timeEast/" -e "s/TS1/$epocEast/" <d >removeEast.patch &&
48 sed -e "s/TS0/$timeGMT/" -e "s/TS1/$epocGMT/" <d >removeGMT.patch &&
50 echo something >something &&
51 >empty
54 for patch in *.patch
56 test_expect_success "test $patch" '
57 rm -f file .git/index &&
58 case "$patch" in
59 create*)
60 # must be able to create
61 git apply --index $patch &&
62 test_cmp file something &&
63 # must notice the file is already there
64 >file &&
65 git add file &&
66 test_must_fail git apply $patch
68 add*)
69 # must be able to create or patch
70 git apply $patch &&
71 test_cmp file something &&
72 >file &&
73 git apply $patch &&
74 test_cmp file something
76 empty*)
77 # must leave an empty file
78 cat something >file &&
79 git add file &&
80 git apply --index $patch &&
81 test -f file &&
82 test_cmp empty file
84 remove*)
85 # must remove the file
86 cat something >file &&
87 git add file &&
88 git apply --index $patch &&
89 ! test -f file
91 esac
93 done
95 test_done