3 test_description
='patching from inconvenient places'
7 test_expect_success
'setup' '
16 patch="$(pwd)/patch" &&
19 printf "%s\n" 1 2 >postimage &&
23 git commit --allow-empty -m basis
26 test_expect_success
'setup: subdir' '
32 cp "$1" objects/file &&
33 cp "$1" sub/dir/file &&
34 cp "$1" sub/dir/b/file &&
35 git add file sub/dir/file sub/dir/b/file objects/file &&
37 cp "$2" sub/dir/file &&
38 cp "$2" sub/dir/b/file &&
39 cp "$2" objects/file &&
40 test_might_fail git update-index --refresh -q
44 test_expect_success
'apply from subdir of toplevel' '
45 cp postimage expected &&
46 reset_subdir other preimage &&
51 test_cmp expected sub/dir/file
54 test_expect_success
'apply --cached from subdir of toplevel' '
55 cp postimage expected &&
56 cp other expected.working &&
57 reset_subdir preimage other &&
60 git apply --cached "$patch"
62 git show :sub/dir/file >actual &&
63 test_cmp expected actual &&
64 test_cmp expected.working sub/dir/file
67 test_expect_success
'apply --index from subdir of toplevel' '
68 cp postimage expected &&
69 reset_subdir preimage other &&
72 test_must_fail git apply --index "$patch"
74 reset_subdir other preimage &&
77 test_must_fail git apply --index "$patch"
79 reset_subdir preimage preimage &&
82 git apply --index "$patch"
84 git show :sub/dir/file >actual &&
85 test_cmp expected actual &&
86 test_cmp expected sub/dir/file
89 test_expect_success
'apply half-broken patch from subdir of toplevel' '
92 test_must_fail git apply <<-EOF
103 test_expect_success
'apply from .git dir' '
104 cp postimage expected &&
105 cp preimage .git/file &&
106 cp preimage .git/objects/file &&
111 test_cmp expected .git/file
114 test_expect_success
'apply from subdir of .git dir' '
115 cp postimage expected &&
116 cp preimage .git/file &&
117 cp preimage .git/objects/file &&
122 test_cmp expected .git/objects/file
125 test_expect_success
'apply --cached from .git dir' '
126 cp postimage expected &&
127 cp other expected.working &&
128 cp other .git/file &&
129 reset_subdir preimage other &&
132 git apply --cached "$patch"
134 git show :file >actual &&
135 test_cmp expected actual &&
136 test_cmp expected.working file &&
137 test_cmp expected.working .git/file
140 test_expect_success
'apply --cached from subdir of .git dir' '
141 cp postimage expected &&
142 cp preimage expected.subdir &&
143 cp other .git/file &&
144 cp other .git/objects/file &&
145 reset_subdir preimage other &&
148 git apply --cached "$patch"
150 git show :file >actual &&
151 git show :objects/file >actual.subdir &&
152 test_cmp expected actual &&
153 test_cmp expected.subdir actual.subdir