add-patch: do not show UI messages on stderr
[git/gitster.git] / t / t4111-apply-subdir.sh
blobe9a87d761d168323ada1e58ecd9df719cc7511b3
1 #!/bin/sh
3 test_description='patching from inconvenient places'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
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 @@
16 EOF
17 patch="$(pwd)/patch" &&
19 echo 1 >preimage &&
20 printf "%s\n" 1 2 >postimage &&
21 echo 3 >other &&
23 test_tick &&
24 git commit --allow-empty -m basis
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 &&
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 &&
49 cd sub/dir &&
50 git apply "$patch"
51 ) &&
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 &&
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
68 test_expect_success 'apply --index from subdir of toplevel' '
69 cp postimage expected &&
70 reset_subdir preimage other &&
72 cd sub/dir &&
73 test_must_fail git apply --index "$patch"
74 ) &&
75 reset_subdir other preimage &&
77 cd sub/dir &&
78 test_must_fail git apply --index "$patch"
79 ) &&
80 reset_subdir preimage preimage &&
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
90 test_expect_success 'apply half-broken patch from subdir of toplevel' '
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 @@
104 test_expect_success 'apply from .git dir' '
105 cp postimage expected &&
106 cp preimage .git/file &&
107 cp preimage .git/objects/file &&
109 cd .git &&
110 git apply "$patch"
111 ) &&
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 &&
120 cd .git/objects &&
121 git apply "$patch"
122 ) &&
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 &&
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
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 &&
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
157 test_done