]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4128-apply-root.sh
Sync with 2.35.5
[thirdparty/git.git] / t / t4128-apply-root.sh
1 #!/bin/sh
2
3 test_description='apply same filename'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup' '
8
9 mkdir -p some/sub/dir &&
10 echo Hello > some/sub/dir/file &&
11 git add some/sub/dir/file &&
12 git commit -m initial &&
13 git tag initial
14
15 '
16
17 cat > patch << EOF
18 diff 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
24 EOF
25
26 test_expect_success 'apply --directory -p (1)' '
27 git apply --directory=some/sub -p3 --index patch &&
28 echo Bello >expect &&
29 git show :some/sub/dir/file >actual &&
30 test_cmp expect actual &&
31 test_cmp expect some/sub/dir/file
32
33 '
34
35 test_expect_success 'apply --directory -p (2) ' '
36
37 git reset --hard initial &&
38 git apply --directory=some/sub/ -p3 --index patch &&
39 echo Bello >expect &&
40 git show :some/sub/dir/file >actual &&
41 test_cmp expect actual &&
42 test_cmp expect some/sub/dir/file
43
44 '
45
46 cat > patch << EOF
47 diff --git a/newfile b/newfile
48 new file mode 100644
49 index 0000000..d95f3ad
50 --- /dev/null
51 +++ b/newfile
52 @@ -0,0 +1 @@
53 +content
54 EOF
55
56 test_expect_success 'apply --directory (new file)' '
57 git reset --hard initial &&
58 git apply --directory=some/sub/dir/ --index patch &&
59 echo content >expect &&
60 git show :some/sub/dir/newfile >actual &&
61 test_cmp expect actual &&
62 test_cmp expect some/sub/dir/newfile
63 '
64
65 cat > patch << EOF
66 diff --git a/c/newfile2 b/c/newfile2
67 new file mode 100644
68 index 0000000..d95f3ad
69 --- /dev/null
70 +++ b/c/newfile2
71 @@ -0,0 +1 @@
72 +content
73 EOF
74
75 test_expect_success 'apply --directory -p (new file)' '
76 git reset --hard initial &&
77 git apply -p2 --directory=some/sub/dir/ --index patch &&
78 echo content >expect &&
79 git show :some/sub/dir/newfile2 >actual &&
80 test_cmp expect actual &&
81 test_cmp expect some/sub/dir/newfile2
82 '
83
84 cat > patch << EOF
85 diff --git a/delfile b/delfile
86 deleted file mode 100644
87 index d95f3ad..0000000
88 --- a/delfile
89 +++ /dev/null
90 @@ -1 +0,0 @@
91 -content
92 EOF
93
94 test_expect_success 'apply --directory (delete file)' '
95 git reset --hard initial &&
96 echo content >some/sub/dir/delfile &&
97 git add some/sub/dir/delfile &&
98 git apply --directory=some/sub/dir/ --index patch &&
99 git ls-files >out &&
100 ! grep delfile out
101 '
102
103 cat > patch << 'EOF'
104 diff --git "a/qu\157tefile" "b/qu\157tefile"
105 new file mode 100644
106 index 0000000..d95f3ad
107 --- /dev/null
108 +++ "b/qu\157tefile"
109 @@ -0,0 +1 @@
110 +content
111 EOF
112
113 test_expect_success 'apply --directory (quoted filename)' '
114 git reset --hard initial &&
115 git apply --directory=some/sub/dir/ --index patch &&
116 echo content >expect &&
117 git show :some/sub/dir/quotefile >actual &&
118 test_cmp expect actual &&
119 test_cmp expect some/sub/dir/quotefile
120 '
121
122 test_done