blob: 8f6aea48d84621ae3b7304636452c724a4bbe5b6 [file] [log] [blame]
Johannes Schindelinc4730f32008-07-01 00:44:47 +01001#!/bin/sh
2
3test_description='apply same filename'
4
5. ./test-lib.sh
6
7test_expect_success 'setup' '
8
9 mkdir -p some/sub/dir &&
10 echo Hello > some/sub/dir/file &&
Junio C Hamano8ee4a6c2008-07-02 15:28:22 -070011 git add some/sub/dir/file &&
12 git commit -m initial &&
13 git tag initial
Johannes Schindelinc4730f32008-07-01 00:44:47 +010014
15'
16
17cat > patch << EOF
18diff a/bla/blub/dir/file b/bla/blub/dir/file
19--- a/bla/blub/dir/file
20+++ b/bla/blub/dir/file
21@@ -1,1 +1,1 @@
22-Hello
23+Bello
24EOF
25
Junio C Hamanof5563882008-07-06 18:36:01 -070026test_expect_success 'apply --directory -p (1)' '
Johannes Schindelinc4730f32008-07-01 00:44:47 +010027
Junio C Hamanof5563882008-07-06 18:36:01 -070028 git apply --directory=some/sub -p3 --index patch &&
Johannes Schindelinc4730f32008-07-01 00:44:47 +010029 test Bello = $(git show :some/sub/dir/file) &&
30 test Bello = $(cat some/sub/dir/file)
31
32'
33
Junio C Hamanof5563882008-07-06 18:36:01 -070034test_expect_success 'apply --directory -p (2) ' '
Junio C Hamano8ee4a6c2008-07-02 15:28:22 -070035
36 git reset --hard initial &&
Junio C Hamanof5563882008-07-06 18:36:01 -070037 git apply --directory=some/sub/ -p3 --index patch &&
Junio C Hamano8ee4a6c2008-07-02 15:28:22 -070038 test Bello = $(git show :some/sub/dir/file) &&
39 test Bello = $(cat some/sub/dir/file)
40
41'
42
Jeff King969c8772008-10-12 00:06:11 -040043cat > patch << EOF
44diff --git a/newfile b/newfile
45new file mode 100644
46index 0000000..d95f3ad
47--- /dev/null
48+++ b/newfile
49@@ -0,0 +1 @@
50+content
51EOF
52
53test_expect_success 'apply --directory (new file)' '
54 git reset --hard initial &&
55 git apply --directory=some/sub/dir/ --index patch &&
56 test content = $(git show :some/sub/dir/newfile) &&
57 test content = $(cat some/sub/dir/newfile)
58'
59
60cat > patch << EOF
61diff --git a/delfile b/delfile
62deleted file mode 100644
63index d95f3ad..0000000
64--- a/delfile
65+++ /dev/null
66@@ -1 +0,0 @@
67-content
68EOF
69
70test_expect_success 'apply --directory (delete file)' '
71 git reset --hard initial &&
72 echo content >some/sub/dir/delfile &&
73 git add some/sub/dir/delfile &&
74 git apply --directory=some/sub/dir/ --index patch &&
Jeff King80bfd762008-10-13 05:35:59 -040075 ! (git ls-files | grep delfile)
Jeff King969c8772008-10-12 00:06:11 -040076'
77
78cat > patch << 'EOF'
79diff --git "a/qu\157tefile" "b/qu\157tefile"
80new file mode 100644
81index 0000000..d95f3ad
82--- /dev/null
83+++ "b/qu\157tefile"
84@@ -0,0 +1 @@
85+content
86EOF
87
88test_expect_success 'apply --directory (quoted filename)' '
89 git reset --hard initial &&
90 git apply --directory=some/sub/dir/ --index patch &&
91 test content = $(git show :some/sub/dir/quotefile) &&
92 test content = $(cat some/sub/dir/quotefile)
93'
94
Johannes Schindelinc4730f32008-07-01 00:44:47 +010095test_done