Merge branch 'js/var-git-shell-path'
[git/debian.git] / t / t4128-apply-root.sh
blobed94c90204e9c2eab135a1c2dcdeb15cf33e214c
1 #!/bin/sh
3 test_description='apply same filename'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' '
10 mkdir -p some/sub/dir &&
11 echo Hello > some/sub/dir/file &&
12 git add some/sub/dir/file &&
13 git commit -m initial &&
14 git tag initial
18 cat > patch << EOF
19 diff a/bla/blub/dir/file b/bla/blub/dir/file
20 --- a/bla/blub/dir/file
21 +++ b/bla/blub/dir/file
22 @@ -1,1 +1,1 @@
23 -Hello
24 +Bello
25 EOF
27 test_expect_success 'apply --directory -p (1)' '
28 git apply --directory=some/sub -p3 --index patch &&
29 echo Bello >expect &&
30 git show :some/sub/dir/file >actual &&
31 test_cmp expect actual &&
32 test_cmp expect some/sub/dir/file
36 test_expect_success 'apply --directory -p (2) ' '
38 git reset --hard initial &&
39 git apply --directory=some/sub/ -p3 --index patch &&
40 echo Bello >expect &&
41 git show :some/sub/dir/file >actual &&
42 test_cmp expect actual &&
43 test_cmp expect some/sub/dir/file
47 cat > patch << EOF
48 diff --git a/newfile b/newfile
49 new file mode 100644
50 index 0000000..d95f3ad
51 --- /dev/null
52 +++ b/newfile
53 @@ -0,0 +1 @@
54 +content
55 EOF
57 test_expect_success 'apply --directory (new file)' '
58 git reset --hard initial &&
59 git apply --directory=some/sub/dir/ --index patch &&
60 echo content >expect &&
61 git show :some/sub/dir/newfile >actual &&
62 test_cmp expect actual &&
63 test_cmp expect some/sub/dir/newfile
66 cat > patch << EOF
67 diff --git a/c/newfile2 b/c/newfile2
68 new file mode 100644
69 index 0000000..d95f3ad
70 --- /dev/null
71 +++ b/c/newfile2
72 @@ -0,0 +1 @@
73 +content
74 EOF
76 test_expect_success 'apply --directory -p (new file)' '
77 git reset --hard initial &&
78 git apply -p2 --directory=some/sub/dir/ --index patch &&
79 echo content >expect &&
80 git show :some/sub/dir/newfile2 >actual &&
81 test_cmp expect actual &&
82 test_cmp expect some/sub/dir/newfile2
85 cat > patch << EOF
86 diff --git a/delfile b/delfile
87 deleted file mode 100644
88 index d95f3ad..0000000
89 --- a/delfile
90 +++ /dev/null
91 @@ -1 +0,0 @@
92 -content
93 EOF
95 test_expect_success 'apply --directory (delete file)' '
96 git reset --hard initial &&
97 echo content >some/sub/dir/delfile &&
98 git add some/sub/dir/delfile &&
99 git apply --directory=some/sub/dir/ --index patch &&
100 git ls-files >out &&
101 ! grep delfile out
104 cat > patch << 'EOF'
105 diff --git "a/qu\157tefile" "b/qu\157tefile"
106 new file mode 100644
107 index 0000000..d95f3ad
108 --- /dev/null
109 +++ "b/qu\157tefile"
110 @@ -0,0 +1 @@
111 +content
114 test_expect_success 'apply --directory (quoted filename)' '
115 git reset --hard initial &&
116 git apply --directory=some/sub/dir/ --index patch &&
117 echo content >expect &&
118 git show :some/sub/dir/quotefile >actual &&
119 test_cmp expect actual &&
120 test_cmp expect some/sub/dir/quotefile
123 test_done