3 test_description
='patching from inconvenient places'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'setup' '
17 patch="$(pwd)/patch" &&
20 printf "%s\n" 1 2 >postimage &&
24 git commit --allow-empty -m basis
27 test_expect_success
'setup: subdir' '
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 &&
38 cp "$2" sub/dir/file &&
39 cp "$2" sub/dir/b/file &&
40 cp "$2" objects/file &&
41 test_might_fail git update-index --refresh -q
45 test_expect_success
'apply from subdir of toplevel' '
46 cp postimage expected &&
47 reset_subdir other preimage &&
52 test_cmp expected sub/dir/file
55 test_expect_success
'apply --cached from subdir of toplevel' '
56 cp postimage expected &&
57 cp other expected.working &&
58 reset_subdir preimage other &&
61 git apply --cached "$patch"
63 git show :sub/dir/file >actual &&
64 test_cmp expected actual &&
65 test_cmp expected.working sub/dir/file
68 test_expect_success
'apply --index from subdir of toplevel' '
69 cp postimage expected &&
70 reset_subdir preimage other &&
73 test_must_fail git apply --index "$patch"
75 reset_subdir other preimage &&
78 test_must_fail git apply --index "$patch"
80 reset_subdir preimage preimage &&
83 git apply --index "$patch"
85 git show :sub/dir/file >actual &&
86 test_cmp expected actual &&
87 test_cmp expected sub/dir/file
90 test_expect_success
'apply half-broken patch from subdir of toplevel' '
93 test_must_fail git apply <<-EOF
104 test_expect_success
'apply from .git dir' '
105 cp postimage expected &&
106 cp preimage .git/file &&
107 cp preimage .git/objects/file &&
112 test_cmp expected .git/file
115 test_expect_success
'apply from subdir of .git dir' '
116 cp postimage expected &&
117 cp preimage .git/file &&
118 cp preimage .git/objects/file &&
123 test_cmp expected .git/objects/file
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 &&
133 git apply --cached "$patch"
135 git show :file >actual &&
136 test_cmp expected actual &&
137 test_cmp expected.working file &&
138 test_cmp expected.working .git/file
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 &&
149 git apply --cached "$patch"
151 git show :file >actual &&
152 git show :objects/file >actual.subdir &&
153 test_cmp expected actual &&
154 test_cmp expected.subdir actual.subdir