core.hidedotfiles: hide '.git' dir by default
[git/dscho.git] / t / t4111-apply-subdir.sh
blob7c398432bad761c1b38c6d15548bed0c389221fd
1 #!/bin/sh
3 test_description='patching from inconvenient places'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 cat >patch <<-\EOF &&
9 diff file.orig file
10 --- a/file.orig
11 +++ b/file
12 @@ -1 +1,2 @@
15 EOF
16 patch="$(pwd)/patch" &&
18 echo 1 >preimage &&
19 printf "%s\n" 1 2 >postimage &&
20 echo 3 >other &&
22 test_tick &&
23 git commit --allow-empty -m basis
26 test_expect_success 'setup: subdir' '
27 reset_subdir() {
28 git reset &&
29 mkdir -p sub/dir/b &&
30 mkdir -p objects &&
31 cp "$1" file &&
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 &&
36 cp "$2" 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 &&
48 cd sub/dir &&
49 git apply "$patch"
50 ) &&
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 &&
59 cd sub/dir &&
60 git apply --cached "$patch"
61 ) &&
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 &&
71 cd sub/dir &&
72 test_must_fail git apply --index "$patch"
73 ) &&
74 reset_subdir other preimage &&
76 cd sub/dir &&
77 test_must_fail git apply --index "$patch"
78 ) &&
79 reset_subdir preimage preimage &&
81 cd sub/dir &&
82 git apply --index "$patch"
83 ) &&
84 git show :sub/dir/file >actual &&
85 test_cmp expected actual &&
86 test_cmp expected sub/dir/file
89 test_expect_success 'apply from .git dir' '
90 cp postimage expected &&
91 cp preimage .git/file &&
92 cp preimage .git/objects/file &&
94 cd .git &&
95 git apply "$patch"
96 ) &&
97 test_cmp expected .git/file
100 test_expect_success 'apply from subdir of .git dir' '
101 cp postimage expected &&
102 cp preimage .git/file &&
103 cp preimage .git/objects/file &&
105 cd .git/objects &&
106 git apply "$patch"
107 ) &&
108 test_cmp expected .git/objects/file
111 test_expect_success 'apply --cached from .git dir' '
112 cp postimage expected &&
113 cp other expected.working &&
114 cp other .git/file &&
115 reset_subdir preimage other &&
117 cd .git &&
118 git apply --cached "$patch"
119 ) &&
120 git show :file >actual &&
121 test_cmp expected actual &&
122 test_cmp expected.working file &&
123 test_cmp expected.working .git/file
126 test_expect_success 'apply --cached from subdir of .git dir' '
127 cp postimage expected &&
128 cp preimage expected.subdir &&
129 cp other .git/file &&
130 cp other .git/objects/file &&
131 reset_subdir preimage other &&
133 cd .git/objects &&
134 git apply --cached "$patch"
135 ) &&
136 git show :file >actual &&
137 git show :objects/file >actual.subdir &&
138 test_cmp expected actual &&
139 test_cmp expected.subdir actual.subdir
142 test_done