]>
Commit | Line | Data |
---|---|---|
9f41a91a JN |
1 | #!/bin/sh |
2 | ||
3 | test_description='patching from inconvenient places' | |
4 | ||
03267e86 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
9f41a91a JN |
6 | . ./test-lib.sh |
7 | ||
8 | test_expect_success 'setup' ' | |
9 | cat >patch <<-\EOF && | |
10 | diff file.orig file | |
11 | --- a/file.orig | |
12 | +++ b/file | |
13 | @@ -1 +1,2 @@ | |
14 | 1 | |
15 | +2 | |
16 | EOF | |
17 | patch="$(pwd)/patch" && | |
18 | ||
19 | echo 1 >preimage && | |
20 | printf "%s\n" 1 2 >postimage && | |
21 | echo 3 >other && | |
22 | ||
23 | test_tick && | |
24 | git commit --allow-empty -m basis | |
25 | ' | |
26 | ||
27 | test_expect_success 'setup: subdir' ' | |
28 | reset_subdir() { | |
29 | git reset && | |
30 | mkdir -p sub/dir/b && | |
31 | mkdir -p objects && | |
32 | cp "$1" file && | |
33 | cp "$1" objects/file && | |
34 | cp "$1" sub/dir/file && | |
35 | cp "$1" sub/dir/b/file && | |
36 | git add file sub/dir/file sub/dir/b/file objects/file && | |
37 | cp "$2" file && | |
38 | cp "$2" sub/dir/file && | |
39 | cp "$2" sub/dir/b/file && | |
60f20d4b JN |
40 | cp "$2" objects/file && |
41 | test_might_fail git update-index --refresh -q | |
9f41a91a JN |
42 | } |
43 | ' | |
44 | ||
45 | test_expect_success 'apply from subdir of toplevel' ' | |
46 | cp postimage expected && | |
47 | reset_subdir other preimage && | |
48 | ( | |
49 | cd sub/dir && | |
50 | git apply "$patch" | |
51 | ) && | |
52 | test_cmp expected sub/dir/file | |
53 | ' | |
54 | ||
55 | test_expect_success 'apply --cached from subdir of toplevel' ' | |
56 | cp postimage expected && | |
57 | cp other expected.working && | |
58 | reset_subdir preimage other && | |
59 | ( | |
60 | cd sub/dir && | |
61 | git apply --cached "$patch" | |
62 | ) && | |
63 | git show :sub/dir/file >actual && | |
64 | test_cmp expected actual && | |
65 | test_cmp expected.working sub/dir/file | |
66 | ' | |
67 | ||
68 | test_expect_success 'apply --index from subdir of toplevel' ' | |
69 | cp postimage expected && | |
70 | reset_subdir preimage other && | |
71 | ( | |
72 | cd sub/dir && | |
73 | test_must_fail git apply --index "$patch" | |
74 | ) && | |
75 | reset_subdir other preimage && | |
76 | ( | |
77 | cd sub/dir && | |
78 | test_must_fail git apply --index "$patch" | |
79 | ) && | |
80 | reset_subdir preimage preimage && | |
81 | ( | |
82 | cd sub/dir && | |
83 | git apply --index "$patch" | |
84 | ) && | |
85 | git show :sub/dir/file >actual && | |
86 | test_cmp expected actual && | |
87 | test_cmp expected sub/dir/file | |
88 | ' | |
89 | ||
212eb96a TR |
90 | test_expect_success 'apply half-broken patch from subdir of toplevel' ' |
91 | ( | |
92 | cd sub/dir && | |
93 | test_must_fail git apply <<-EOF | |
94 | --- sub/dir/file | |
95 | +++ sub/dir/file | |
96 | @@ -1,0 +1,0 @@ | |
97 | --- file_in_root | |
98 | +++ file_in_root | |
99 | @@ -1,0 +1,0 @@ | |
100 | EOF | |
101 | ) | |
102 | ' | |
103 | ||
9f41a91a JN |
104 | test_expect_success 'apply from .git dir' ' |
105 | cp postimage expected && | |
106 | cp preimage .git/file && | |
a48fcd83 | 107 | cp preimage .git/objects/file && |
9f41a91a JN |
108 | ( |
109 | cd .git && | |
110 | git apply "$patch" | |
111 | ) && | |
112 | test_cmp expected .git/file | |
113 | ' | |
114 | ||
8fc0ae80 | 115 | test_expect_success 'apply from subdir of .git dir' ' |
9f41a91a JN |
116 | cp postimage expected && |
117 | cp preimage .git/file && | |
a48fcd83 | 118 | cp preimage .git/objects/file && |
9f41a91a JN |
119 | ( |
120 | cd .git/objects && | |
121 | git apply "$patch" | |
122 | ) && | |
123 | test_cmp expected .git/objects/file | |
124 | ' | |
125 | ||
126 | test_expect_success 'apply --cached from .git dir' ' | |
127 | cp postimage expected && | |
128 | cp other expected.working && | |
129 | cp other .git/file && | |
130 | reset_subdir preimage other && | |
131 | ( | |
132 | cd .git && | |
133 | git apply --cached "$patch" | |
134 | ) && | |
135 | git show :file >actual && | |
136 | test_cmp expected actual && | |
137 | test_cmp expected.working file && | |
138 | test_cmp expected.working .git/file | |
139 | ' | |
140 | ||
141 | test_expect_success 'apply --cached from subdir of .git dir' ' | |
142 | cp postimage expected && | |
143 | cp preimage expected.subdir && | |
144 | cp other .git/file && | |
145 | cp other .git/objects/file && | |
146 | reset_subdir preimage other && | |
147 | ( | |
148 | cd .git/objects && | |
149 | git apply --cached "$patch" | |
150 | ) && | |
151 | git show :file >actual && | |
152 | git show :objects/file >actual.subdir && | |
153 | test_cmp expected actual && | |
154 | test_cmp expected.subdir actual.subdir | |
155 | ' | |
156 | ||
157 | test_done |