Charles Bailey | 05e934b | 2008-02-21 23:31:56 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Charles Bailey |
| 4 | # |
| 5 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 6 | test_description='git mergetool |
Charles Bailey | 05e934b | 2008-02-21 23:31:56 +0000 | [diff] [blame] | 7 | |
| 8 | Testing basic merge tool invocation' |
| 9 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 10 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 11 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 12 | |
Charles Bailey | 05e934b | 2008-02-21 23:31:56 +0000 | [diff] [blame] | 13 | . ./test-lib.sh |
| 14 | |
Charles Bailey | b9b5078 | 2009-01-30 23:20:10 +0000 | [diff] [blame] | 15 | # All the mergetool test work by checking out a temporary branch based |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 16 | # off 'branch1' and then merging in main and checking the results of |
Charles Bailey | b9b5078 | 2009-01-30 23:20:10 +0000 | [diff] [blame] | 17 | # running mergetool |
| 18 | |
Charles Bailey | 05e934b | 2008-02-21 23:31:56 +0000 | [diff] [blame] | 19 | test_expect_success 'setup' ' |
David Aguilar | f9e4308 | 2014-10-15 01:35:20 -0700 | [diff] [blame] | 20 | test_config rerere.enabled true && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 21 | echo main >file1 && |
| 22 | echo main spaced >"spaced name" && |
| 23 | echo main file11 >file11 && |
| 24 | echo main file12 >file12 && |
| 25 | echo main file13 >file13 && |
| 26 | echo main file14 >file14 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 27 | mkdir subdir && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 28 | echo main sub >subdir/file3 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 29 | test_create_repo submod && |
| 30 | ( |
| 31 | cd submod && |
| 32 | : >foo && |
| 33 | git add foo && |
| 34 | git commit -m "Add foo" |
| 35 | ) && |
Ævar Arnfjörð Bjarmason | 23fb328 | 2022-11-16 00:40:14 +0100 | [diff] [blame] | 36 | git submodule add file:///dev/null submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 37 | git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod && |
| 38 | git commit -m "add initial versions" && |
Charles Bailey | b9b5078 | 2009-01-30 23:20:10 +0000 | [diff] [blame] | 39 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 40 | git checkout -b branch1 main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 41 | git submodule update -N && |
| 42 | echo branch1 change >file1 && |
| 43 | echo branch1 newfile >file2 && |
| 44 | echo branch1 spaced >"spaced name" && |
| 45 | echo branch1 both added >both && |
| 46 | echo branch1 change file11 >file11 && |
| 47 | echo branch1 change file13 >file13 && |
| 48 | echo branch1 sub >subdir/file3 && |
| 49 | ( |
| 50 | cd submod && |
| 51 | echo branch1 submodule >bar && |
| 52 | git add bar && |
| 53 | git commit -m "Add bar on branch1" && |
| 54 | git checkout -b submod-branch1 |
| 55 | ) && |
| 56 | git add file1 "spaced name" file11 file13 file2 subdir/file3 submod && |
| 57 | git add both && |
| 58 | git rm file12 && |
| 59 | git commit -m "branch1 changes" && |
Charles Bailey | b9b5078 | 2009-01-30 23:20:10 +0000 | [diff] [blame] | 60 | |
Richard Hansen | 157acfc | 2017-01-10 15:41:52 -0500 | [diff] [blame] | 61 | git checkout -b delete-base branch1 && |
| 62 | mkdir -p a/a && |
Eric Sunshine | 0590ff2 | 2018-07-01 20:23:42 -0400 | [diff] [blame] | 63 | test_write_lines one two 3 4 >a/a/file.txt && |
Richard Hansen | 157acfc | 2017-01-10 15:41:52 -0500 | [diff] [blame] | 64 | git add a/a/file.txt && |
| 65 | git commit -m"base file" && |
| 66 | git checkout -b move-to-b delete-base && |
| 67 | mkdir -p b/b && |
| 68 | git mv a/a/file.txt b/b/file.txt && |
Eric Sunshine | 0590ff2 | 2018-07-01 20:23:42 -0400 | [diff] [blame] | 69 | test_write_lines one two 4 >b/b/file.txt && |
Richard Hansen | 157acfc | 2017-01-10 15:41:52 -0500 | [diff] [blame] | 70 | git commit -a -m"move to b" && |
| 71 | git checkout -b move-to-c delete-base && |
| 72 | mkdir -p c/c && |
| 73 | git mv a/a/file.txt c/c/file.txt && |
Eric Sunshine | 0590ff2 | 2018-07-01 20:23:42 -0400 | [diff] [blame] | 74 | test_write_lines one two 3 >c/c/file.txt && |
Richard Hansen | 157acfc | 2017-01-10 15:41:52 -0500 | [diff] [blame] | 75 | git commit -a -m"move to c" && |
| 76 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 77 | git checkout -b stash1 main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 78 | echo stash1 change file11 >file11 && |
| 79 | git add file11 && |
| 80 | git commit -m "stash1 changes" && |
Phil Hord | 79dc2d0 | 2012-07-10 18:52:27 -0400 | [diff] [blame] | 81 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 82 | git checkout -b stash2 main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 83 | echo stash2 change file11 >file11 && |
| 84 | git add file11 && |
| 85 | git commit -m "stash2 changes" && |
Phil Hord | 79dc2d0 | 2012-07-10 18:52:27 -0400 | [diff] [blame] | 86 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 87 | git checkout main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 88 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 89 | echo main updated >file1 && |
| 90 | echo main new >file2 && |
| 91 | echo main updated spaced >"spaced name" && |
| 92 | echo main both added >both && |
| 93 | echo main updated file12 >file12 && |
| 94 | echo main updated file14 >file14 && |
| 95 | echo main new sub >subdir/file3 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 96 | ( |
| 97 | cd submod && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 98 | echo main submodule >bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 99 | git add bar && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 100 | git commit -m "Add bar on main" && |
| 101 | git checkout -b submod-main |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 102 | ) && |
| 103 | git add file1 "spaced name" file12 file14 file2 subdir/file3 submod && |
| 104 | git add both && |
| 105 | git rm file11 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 106 | git commit -m "main updates" && |
Charles Bailey | b9b5078 | 2009-01-30 23:20:10 +0000 | [diff] [blame] | 107 | |
Richard Hansen | 157acfc | 2017-01-10 15:41:52 -0500 | [diff] [blame] | 108 | git clean -fdx && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 109 | git checkout -b order-file-start main && |
Richard Hansen | 157acfc | 2017-01-10 15:41:52 -0500 | [diff] [blame] | 110 | echo start >a && |
| 111 | echo start >b && |
| 112 | git add a b && |
| 113 | git commit -m start && |
| 114 | git checkout -b order-file-side1 order-file-start && |
| 115 | echo side1 >a && |
| 116 | echo side1 >b && |
| 117 | git add a b && |
| 118 | git commit -m side1 && |
| 119 | git checkout -b order-file-side2 order-file-start && |
| 120 | echo side2 >a && |
| 121 | echo side2 >b && |
| 122 | git add a b && |
| 123 | git commit -m side2 && |
| 124 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 125 | git config merge.tool mytool && |
| 126 | git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && |
| 127 | git config mergetool.mytool.trustExitCode true && |
| 128 | git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" && |
| 129 | git config mergetool.mybase.trustExitCode true |
Charles Bailey | 05e934b | 2008-02-21 23:31:56 +0000 | [diff] [blame] | 130 | ' |
| 131 | |
| 132 | test_expect_success 'custom mergetool' ' |
Richard Hansen | c3ad312 | 2017-01-10 15:41:55 -0500 | [diff] [blame] | 133 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 134 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 135 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 136 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 137 | yes "" | git mergetool both && |
| 138 | yes "" | git mergetool file1 file1 && |
| 139 | yes "" | git mergetool file2 "spaced name" && |
| 140 | yes "" | git mergetool subdir/file3 && |
| 141 | yes "d" | git mergetool file11 && |
| 142 | yes "d" | git mergetool file12 && |
| 143 | yes "l" | git mergetool submod && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 144 | echo "main updated" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 145 | test_cmp expect file1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 146 | echo "main new" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 147 | test_cmp expect file2 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 148 | echo "main new sub" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 149 | test_cmp expect subdir/file3 && |
| 150 | echo "branch1 submodule" >expect && |
| 151 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 152 | git commit -m "branch1 resolved with mergetool" |
Charles Bailey | 0ec7b6c | 2009-01-21 22:57:48 +0000 | [diff] [blame] | 153 | ' |
| 154 | |
Denton Liu | 57d93c1 | 2019-04-24 15:46:59 -0700 | [diff] [blame] | 155 | test_expect_success 'gui mergetool' ' |
| 156 | test_config merge.guitool myguitool && |
| 157 | test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" && |
| 158 | test_config mergetool.myguitool.trustExitCode true && |
| 159 | test_when_finished "git reset --hard" && |
| 160 | git checkout -b test$test_count branch1 && |
| 161 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 162 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 163 | yes "" | git mergetool --gui both && |
| 164 | yes "" | git mergetool -g file1 file1 && |
| 165 | yes "" | git mergetool --gui file2 "spaced name" && |
| 166 | yes "" | git mergetool --gui subdir/file3 && |
| 167 | yes "d" | git mergetool --gui file11 && |
| 168 | yes "d" | git mergetool --gui file12 && |
| 169 | yes "l" | git mergetool --gui submod && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 170 | echo "gui main updated" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 171 | test_cmp expect file1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 172 | echo "gui main new" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 173 | test_cmp expect file2 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 174 | echo "gui main new sub" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 175 | test_cmp expect subdir/file3 && |
| 176 | echo "branch1 submodule" >expect && |
| 177 | test_cmp expect submod/bar && |
Denton Liu | 57d93c1 | 2019-04-24 15:46:59 -0700 | [diff] [blame] | 178 | git commit -m "branch1 resolved with mergetool" |
| 179 | ' |
| 180 | |
Denton Liu | 60aced3 | 2019-04-29 02:21:14 -0400 | [diff] [blame] | 181 | test_expect_success 'gui mergetool without merge.guitool set falls back to merge.tool' ' |
| 182 | test_when_finished "git reset --hard" && |
| 183 | git checkout -b test$test_count branch1 && |
| 184 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 185 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 186 | yes "" | git mergetool --gui both && |
| 187 | yes "" | git mergetool -g file1 file1 && |
| 188 | yes "" | git mergetool --gui file2 "spaced name" && |
| 189 | yes "" | git mergetool --gui subdir/file3 && |
| 190 | yes "d" | git mergetool --gui file11 && |
| 191 | yes "d" | git mergetool --gui file12 && |
| 192 | yes "l" | git mergetool --gui submod && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 193 | echo "main updated" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 194 | test_cmp expect file1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 195 | echo "main new" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 196 | test_cmp expect file2 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 197 | echo "main new sub" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 198 | test_cmp expect subdir/file3 && |
| 199 | echo "branch1 submodule" >expect && |
| 200 | test_cmp expect submod/bar && |
Denton Liu | 60aced3 | 2019-04-29 02:21:14 -0400 | [diff] [blame] | 201 | git commit -m "branch1 resolved with mergetool" |
| 202 | ' |
| 203 | |
Charles Bailey | 0ec7b6c | 2009-01-21 22:57:48 +0000 | [diff] [blame] | 204 | test_expect_success 'mergetool crlf' ' |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 205 | test_when_finished "git reset --hard" && |
| 206 | # This test_config line must go after the above reset line so that |
| 207 | # core.autocrlf is unconfigured before reset runs. (The |
| 208 | # test_config command uses test_when_finished internally and |
| 209 | # test_when_finished is LIFO.) |
David Aguilar | f9e4308 | 2014-10-15 01:35:20 -0700 | [diff] [blame] | 210 | test_config core.autocrlf true && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 211 | git checkout -b test$test_count branch1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 212 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 213 | yes "" | git mergetool file1 && |
| 214 | yes "" | git mergetool file2 && |
| 215 | yes "" | git mergetool "spaced name" && |
| 216 | yes "" | git mergetool both && |
| 217 | yes "" | git mergetool subdir/file3 && |
| 218 | yes "d" | git mergetool file11 && |
| 219 | yes "d" | git mergetool file12 && |
| 220 | yes "r" | git mergetool submod && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 221 | test "$(printf x | cat file1 -)" = "$(printf "main updated\r\nx")" && |
| 222 | test "$(printf x | cat file2 -)" = "$(printf "main new\r\nx")" && |
| 223 | test "$(printf x | cat subdir/file3 -)" = "$(printf "main new sub\r\nx")" && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 224 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 225 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 226 | test_cmp expect submod/bar && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 227 | git commit -m "branch1 resolved with mergetool - autocrlf" |
Charles Bailey | 05e934b | 2008-02-21 23:31:56 +0000 | [diff] [blame] | 228 | ' |
| 229 | |
Charles Bailey | ff4a185 | 2009-01-30 23:20:11 +0000 | [diff] [blame] | 230 | test_expect_success 'mergetool in subdir' ' |
Richard Hansen | c3ad312 | 2017-01-10 15:41:55 -0500 | [diff] [blame] | 231 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 232 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 233 | git submodule update -N && |
| 234 | ( |
| 235 | cd subdir && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 236 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 237 | yes "" | git mergetool file3 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 238 | echo "main new sub" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 239 | test_cmp expect file3 |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 240 | ) |
Charles Bailey | b9b5078 | 2009-01-30 23:20:10 +0000 | [diff] [blame] | 241 | ' |
| 242 | |
David Aguilar | bb0a484 | 2010-08-17 02:22:46 -0700 | [diff] [blame] | 243 | test_expect_success 'mergetool on file in parent dir' ' |
Richard Hansen | c3ad312 | 2017-01-10 15:41:55 -0500 | [diff] [blame] | 244 | test_when_finished "git reset --hard" && |
Richard Hansen | fef6c06 | 2017-01-10 15:41:58 -0500 | [diff] [blame] | 245 | git checkout -b test$test_count branch1 && |
Richard Hansen | b696ac9 | 2017-01-10 15:41:54 -0500 | [diff] [blame] | 246 | git submodule update -N && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 247 | ( |
| 248 | cd subdir && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 249 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 250 | yes "" | git mergetool file3 && |
| 251 | yes "" | git mergetool ../file1 && |
| 252 | yes "" | git mergetool ../file2 ../spaced\ name && |
| 253 | yes "" | git mergetool ../both && |
| 254 | yes "d" | git mergetool ../file11 && |
| 255 | yes "d" | git mergetool ../file12 && |
| 256 | yes "l" | git mergetool ../submod && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 257 | echo "main updated" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 258 | test_cmp expect ../file1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 259 | echo "main new" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 260 | test_cmp expect ../file2 && |
| 261 | echo "branch1 submodule" >expect && |
| 262 | test_cmp expect ../submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 263 | git commit -m "branch1 resolved with mergetool - subdir" |
| 264 | ) |
David Aguilar | bb0a484 | 2010-08-17 02:22:46 -0700 | [diff] [blame] | 265 | ' |
| 266 | |
| 267 | test_expect_success 'mergetool skips autoresolved' ' |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 268 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 269 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 270 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 271 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 272 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 273 | yes "d" | git mergetool file11 && |
| 274 | yes "d" | git mergetool file12 && |
| 275 | yes "l" | git mergetool submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 276 | output="$(git mergetool --no-prompt)" && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 277 | test "$output" = "No files need merging" |
David Aguilar | bb0a484 | 2010-08-17 02:22:46 -0700 | [diff] [blame] | 278 | ' |
| 279 | |
Richard Hansen | b9ebb65 | 2017-01-10 15:42:00 -0500 | [diff] [blame] | 280 | test_expect_success 'mergetool merges all from subdir (rerere disabled)' ' |
Richard Hansen | c3ad312 | 2017-01-10 15:41:55 -0500 | [diff] [blame] | 281 | test_when_finished "git reset --hard" && |
Richard Hansen | fef6c06 | 2017-01-10 15:41:58 -0500 | [diff] [blame] | 282 | git checkout -b test$test_count branch1 && |
John Keeping | 1a9a23e | 2015-09-05 14:12:45 +0100 | [diff] [blame] | 283 | test_config rerere.enabled false && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 284 | ( |
| 285 | cd subdir && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 286 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 287 | yes "r" | git mergetool ../submod && |
| 288 | yes "d" "d" | git mergetool --no-prompt && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 289 | echo "main updated" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 290 | test_cmp expect ../file1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 291 | echo "main new" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 292 | test_cmp expect ../file2 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 293 | echo "main new sub" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 294 | test_cmp expect file3 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 295 | ( cd .. && git submodule update -N ) && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 296 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 297 | test_cmp expect ../submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 298 | git commit -m "branch2 resolved by mergetool from subdir" |
| 299 | ) |
David Aguilar | bb0a484 | 2010-08-17 02:22:46 -0700 | [diff] [blame] | 300 | ' |
Charles Bailey | b9b5078 | 2009-01-30 23:20:10 +0000 | [diff] [blame] | 301 | |
Richard Hansen | d0e0cfe | 2017-01-10 15:42:02 -0500 | [diff] [blame] | 302 | test_expect_success 'mergetool merges all from subdir (rerere enabled)' ' |
Richard Hansen | b9ebb65 | 2017-01-10 15:42:00 -0500 | [diff] [blame] | 303 | test_when_finished "git reset --hard" && |
| 304 | git checkout -b test$test_count branch1 && |
David Aguilar | f9e4308 | 2014-10-15 01:35:20 -0700 | [diff] [blame] | 305 | test_config rerere.enabled true && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 306 | rm -rf .git/rr-cache && |
Richard Hansen | b9ebb65 | 2017-01-10 15:42:00 -0500 | [diff] [blame] | 307 | ( |
| 308 | cd subdir && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 309 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 310 | yes "r" | git mergetool ../submod && |
| 311 | yes "d" "d" | git mergetool --no-prompt && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 312 | echo "main updated" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 313 | test_cmp expect ../file1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 314 | echo "main new" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 315 | test_cmp expect ../file2 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 316 | echo "main new sub" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 317 | test_cmp expect file3 && |
Richard Hansen | b9ebb65 | 2017-01-10 15:42:00 -0500 | [diff] [blame] | 318 | ( cd .. && git submodule update -N ) && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 319 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 320 | test_cmp expect ../submod/bar && |
Richard Hansen | b9ebb65 | 2017-01-10 15:42:00 -0500 | [diff] [blame] | 321 | git commit -m "branch2 resolved by mergetool from subdir" |
| 322 | ) |
| 323 | ' |
| 324 | |
Martin von Zweigbergk | 2f59c94 | 2011-02-16 05:47:45 -0500 | [diff] [blame] | 325 | test_expect_success 'mergetool skips resolved paths when rerere is active' ' |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 326 | test_when_finished "git reset --hard" && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 327 | test_config rerere.enabled true && |
| 328 | rm -rf .git/rr-cache && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 329 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 330 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 331 | test_must_fail git merge main && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 332 | yes "l" | git mergetool --no-prompt submod && |
| 333 | yes "d" "d" | git mergetool --no-prompt && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 334 | git submodule update -N && |
| 335 | output="$(yes "n" | git mergetool --no-prompt)" && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 336 | test "$output" = "No files need merging" |
Martin von Zweigbergk | 2f59c94 | 2011-02-16 05:47:45 -0500 | [diff] [blame] | 337 | ' |
| 338 | |
Phil Hord | 743bf6d | 2012-07-10 18:52:28 -0400 | [diff] [blame] | 339 | test_expect_success 'conflicted stash sets up rerere' ' |
Richard Hansen | c3ad312 | 2017-01-10 15:41:55 -0500 | [diff] [blame] | 340 | test_when_finished "git reset --hard" && |
David Aguilar | f9e4308 | 2014-10-15 01:35:20 -0700 | [diff] [blame] | 341 | test_config rerere.enabled true && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 342 | git checkout stash1 && |
| 343 | echo "Conflicting stash content" >file11 && |
| 344 | git stash && |
Phil Hord | 79dc2d0 | 2012-07-10 18:52:27 -0400 | [diff] [blame] | 345 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 346 | git checkout --detach stash2 && |
| 347 | test_must_fail git stash apply && |
Phil Hord | 79dc2d0 | 2012-07-10 18:52:27 -0400 | [diff] [blame] | 348 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 349 | test -n "$(git ls-files -u)" && |
| 350 | conflicts="$(git rerere remaining)" && |
| 351 | test "$conflicts" = "file11" && |
| 352 | output="$(git mergetool --no-prompt)" && |
| 353 | test "$output" != "No files need merging" && |
Phil Hord | 79dc2d0 | 2012-07-10 18:52:27 -0400 | [diff] [blame] | 354 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 355 | git commit -am "save the stash resolution" && |
Phil Hord | 79dc2d0 | 2012-07-10 18:52:27 -0400 | [diff] [blame] | 356 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 357 | git reset --hard stash2 && |
| 358 | test_must_fail git stash apply && |
Phil Hord | 79dc2d0 | 2012-07-10 18:52:27 -0400 | [diff] [blame] | 359 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 360 | test -n "$(git ls-files -u)" && |
| 361 | conflicts="$(git rerere remaining)" && |
| 362 | test -z "$conflicts" && |
| 363 | output="$(git mergetool --no-prompt)" && |
| 364 | test "$output" = "No files need merging" |
Phil Hord | 79dc2d0 | 2012-07-10 18:52:27 -0400 | [diff] [blame] | 365 | ' |
| 366 | |
Jonathon Mah | 3e8e691 | 2011-09-15 19:12:10 -0700 | [diff] [blame] | 367 | test_expect_success 'mergetool takes partial path' ' |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 368 | test_when_finished "git reset --hard" && |
David Aguilar | f9e4308 | 2014-10-15 01:35:20 -0700 | [diff] [blame] | 369 | test_config rerere.enabled false && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 370 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 371 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 372 | test_must_fail git merge main && |
Jonathon Mah | 3e8e691 | 2011-09-15 19:12:10 -0700 | [diff] [blame] | 373 | |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 374 | yes "" | git mergetool subdir && |
Jonathon Mah | 3e8e691 | 2011-09-15 19:12:10 -0700 | [diff] [blame] | 375 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 376 | echo "main new sub" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 377 | test_cmp expect subdir/file3 |
Jonathon Mah | 3e8e691 | 2011-09-15 19:12:10 -0700 | [diff] [blame] | 378 | ' |
| 379 | |
David Aguilar | faaab8d | 2016-03-09 23:13:58 -0800 | [diff] [blame] | 380 | test_expect_success 'mergetool delete/delete conflict' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 381 | test_when_finished "git reset --hard" && |
Richard Hansen | 61b76d2 | 2017-01-10 15:41:57 -0500 | [diff] [blame] | 382 | git checkout -b test$test_count move-to-c && |
David Aguilar | faaab8d | 2016-03-09 23:13:58 -0800 | [diff] [blame] | 383 | test_must_fail git merge move-to-b && |
| 384 | echo d | git mergetool a/a/file.txt && |
| 385 | ! test -f a/a/file.txt && |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 386 | git reset --hard && |
David Aguilar | faaab8d | 2016-03-09 23:13:58 -0800 | [diff] [blame] | 387 | test_must_fail git merge move-to-b && |
| 388 | echo m | git mergetool a/a/file.txt && |
| 389 | test -f b/b/file.txt && |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 390 | git reset --hard && |
David Aguilar | faaab8d | 2016-03-09 23:13:58 -0800 | [diff] [blame] | 391 | test_must_fail git merge move-to-b && |
| 392 | ! echo a | git mergetool a/a/file.txt && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 393 | ! test -f a/a/file.txt |
David Aguilar | faaab8d | 2016-03-09 23:13:58 -0800 | [diff] [blame] | 394 | ' |
| 395 | |
| 396 | test_expect_success 'mergetool produces no errors when keepBackup is used' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 397 | test_when_finished "git reset --hard" && |
Richard Hansen | fef6c06 | 2017-01-10 15:41:58 -0500 | [diff] [blame] | 398 | git checkout -b test$test_count move-to-c && |
David Aguilar | faaab8d | 2016-03-09 23:13:58 -0800 | [diff] [blame] | 399 | test_config mergetool.keepBackup true && |
| 400 | test_must_fail git merge move-to-b && |
David Aguilar | faaab8d | 2016-03-09 23:13:58 -0800 | [diff] [blame] | 401 | echo d | git mergetool a/a/file.txt 2>actual && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 402 | test_must_be_empty actual && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 403 | ! test -d a |
David Aguilar | a298604 | 2016-03-09 23:13:59 -0800 | [diff] [blame] | 404 | ' |
| 405 | |
| 406 | test_expect_success 'mergetool honors tempfile config for deleted files' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 407 | test_when_finished "git reset --hard" && |
Richard Hansen | fef6c06 | 2017-01-10 15:41:58 -0500 | [diff] [blame] | 408 | git checkout -b test$test_count move-to-c && |
David Aguilar | a298604 | 2016-03-09 23:13:59 -0800 | [diff] [blame] | 409 | test_config mergetool.keepTemporaries false && |
| 410 | test_must_fail git merge move-to-b && |
| 411 | echo d | git mergetool a/a/file.txt && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 412 | ! test -d a |
David Aguilar | a298604 | 2016-03-09 23:13:59 -0800 | [diff] [blame] | 413 | ' |
| 414 | |
| 415 | test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 416 | test_when_finished "git reset --hard" && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 417 | test_when_finished "git clean -fdx" && |
Richard Hansen | fef6c06 | 2017-01-10 15:41:58 -0500 | [diff] [blame] | 418 | git checkout -b test$test_count move-to-c && |
David Aguilar | a298604 | 2016-03-09 23:13:59 -0800 | [diff] [blame] | 419 | test_config mergetool.keepTemporaries true && |
| 420 | test_must_fail git merge move-to-b && |
Eric Sunshine | 0590ff2 | 2018-07-01 20:23:42 -0400 | [diff] [blame] | 421 | ! test_write_lines a n | git mergetool a/a/file.txt && |
David Aguilar | a298604 | 2016-03-09 23:13:59 -0800 | [diff] [blame] | 422 | test -d a/a && |
| 423 | cat >expect <<-\EOF && |
| 424 | file_BASE_.txt |
| 425 | file_LOCAL_.txt |
| 426 | file_REMOTE_.txt |
| 427 | EOF |
| 428 | ls -1 a/a | sed -e "s/[0-9]*//g" >actual && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 429 | test_cmp expect actual |
David Aguilar | faaab8d | 2016-03-09 23:13:58 -0800 | [diff] [blame] | 430 | ' |
| 431 | |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 432 | test_expect_success 'deleted vs modified submodule' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 433 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 434 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 435 | git submodule update -N && |
| 436 | mv submod submod-movedaside && |
| 437 | git rm --cached submod && |
| 438 | git commit -m "Submodule deleted from branch" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 439 | git checkout -b test$test_count.a test$test_count && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 440 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 441 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 442 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
| 443 | yes "" | git mergetool both && |
| 444 | yes "d" | git mergetool file11 file12 && |
| 445 | yes "r" | git mergetool submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 446 | rmdir submod && mv submod-movedaside submod && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 447 | echo "branch1 submodule" >expect && |
| 448 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 449 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 450 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 451 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 452 | output="$(git mergetool --no-prompt)" && |
| 453 | test "$output" = "No files need merging" && |
| 454 | git commit -m "Merge resolved by keeping module" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 455 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 456 | mv submod submod-movedaside && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 457 | git checkout -b test$test_count.b test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 458 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 459 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 460 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 461 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
| 462 | yes "" | git mergetool both && |
| 463 | yes "d" | git mergetool file11 file12 && |
| 464 | yes "l" | git mergetool submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 465 | test ! -e submod && |
| 466 | output="$(git mergetool --no-prompt)" && |
| 467 | test "$output" = "No files need merging" && |
| 468 | git commit -m "Merge resolved by deleting module" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 469 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 470 | mv submod-movedaside submod && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 471 | git checkout -b test$test_count.c main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 472 | git submodule update -N && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 473 | test_must_fail git merge test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 474 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 475 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
| 476 | yes "" | git mergetool both && |
| 477 | yes "d" | git mergetool file11 file12 && |
| 478 | yes "r" | git mergetool submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 479 | test ! -e submod && |
| 480 | test -d submod.orig && |
| 481 | git submodule update -N && |
| 482 | output="$(git mergetool --no-prompt)" && |
| 483 | test "$output" = "No files need merging" && |
| 484 | git commit -m "Merge resolved by deleting module" && |
| 485 | mv submod.orig submod && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 486 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 487 | git checkout -b test$test_count.d main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 488 | git submodule update -N && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 489 | test_must_fail git merge test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 490 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 491 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
| 492 | yes "" | git mergetool both && |
| 493 | yes "d" | git mergetool file11 file12 && |
| 494 | yes "l" | git mergetool submod && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 495 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 496 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 497 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 498 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 499 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 500 | output="$(git mergetool --no-prompt)" && |
| 501 | test "$output" = "No files need merging" && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 502 | git commit -m "Merge resolved by keeping module" |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 503 | ' |
| 504 | |
| 505 | test_expect_success 'file vs modified submodule' ' |
Richard Hansen | c3ad312 | 2017-01-10 15:41:55 -0500 | [diff] [blame] | 506 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 507 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 508 | git submodule update -N && |
| 509 | mv submod submod-movedaside && |
| 510 | git rm --cached submod && |
| 511 | echo not a submodule >submod && |
| 512 | git add submod && |
| 513 | git commit -m "Submodule path becomes file" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 514 | git checkout -b test$test_count.a branch1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 515 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 516 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 517 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
| 518 | yes "" | git mergetool both && |
| 519 | yes "d" | git mergetool file11 file12 && |
| 520 | yes "r" | git mergetool submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 521 | rmdir submod && mv submod-movedaside submod && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 522 | echo "branch1 submodule" >expect && |
| 523 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 524 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 525 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 526 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 527 | output="$(git mergetool --no-prompt)" && |
| 528 | test "$output" = "No files need merging" && |
| 529 | git commit -m "Merge resolved by keeping module" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 530 | |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 531 | mv submod submod-movedaside && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 532 | git checkout -b test$test_count.b test$test_count && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 533 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 534 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 535 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
| 536 | yes "" | git mergetool both && |
| 537 | yes "d" | git mergetool file11 file12 && |
Elijah Newren | ef52778 | 2020-10-26 17:01:37 +0000 | [diff] [blame] | 538 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
| 539 | then |
| 540 | yes "c" | git mergetool submod~HEAD && |
| 541 | git rm submod && |
| 542 | git mv submod~HEAD submod |
| 543 | else |
| 544 | yes "l" | git mergetool submod |
| 545 | fi && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 546 | git submodule update -N && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 547 | echo "not a submodule" >expect && |
| 548 | test_cmp expect submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 549 | output="$(git mergetool --no-prompt)" && |
| 550 | test "$output" = "No files need merging" && |
| 551 | git commit -m "Merge resolved by keeping file" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 552 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 553 | git checkout -b test$test_count.c main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 554 | rmdir submod && mv submod-movedaside submod && |
| 555 | test ! -e submod.orig && |
| 556 | git submodule update -N && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 557 | test_must_fail git merge test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 558 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 559 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
| 560 | yes "" | git mergetool both && |
| 561 | yes "d" | git mergetool file11 file12 && |
Elijah Newren | ef52778 | 2020-10-26 17:01:37 +0000 | [diff] [blame] | 562 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
| 563 | then |
| 564 | mv submod submod.orig && |
| 565 | git rm --cached submod && |
| 566 | yes "c" | git mergetool submod~test19 && |
| 567 | git mv submod~test19 submod |
| 568 | else |
| 569 | yes "r" | git mergetool submod |
| 570 | fi && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 571 | test -d submod.orig && |
| 572 | git submodule update -N && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 573 | echo "not a submodule" >expect && |
| 574 | test_cmp expect submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 575 | output="$(git mergetool --no-prompt)" && |
| 576 | test "$output" = "No files need merging" && |
| 577 | git commit -m "Merge resolved by keeping file" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 578 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 579 | git checkout -b test$test_count.d main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 580 | rmdir submod && mv submod.orig submod && |
| 581 | git submodule update -N && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 582 | test_must_fail git merge test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 583 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 584 | yes "" | git mergetool file1 file2 spaced\ name subdir/file3 && |
| 585 | yes "" | git mergetool both && |
| 586 | yes "d" | git mergetool file11 file12 && |
| 587 | yes "l" | git mergetool submod && |
Elijah Newren | ef52778 | 2020-10-26 17:01:37 +0000 | [diff] [blame] | 588 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
| 589 | then |
| 590 | yes "d" | git mergetool submod~test19 |
| 591 | fi && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 592 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 593 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 594 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 595 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 596 | test_cmp expect submod/bar && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 597 | output="$(git mergetool --no-prompt)" && |
| 598 | test "$output" = "No files need merging" && |
| 599 | git commit -m "Merge resolved by keeping module" |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 600 | ' |
| 601 | |
| 602 | test_expect_success 'submodule in subdirectory' ' |
Richard Hansen | c3ad312 | 2017-01-10 15:41:55 -0500 | [diff] [blame] | 603 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 604 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 605 | git submodule update -N && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 606 | ( |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 607 | cd subdir && |
| 608 | test_create_repo subdir_module && |
| 609 | ( |
| 610 | cd subdir_module && |
| 611 | : >file15 && |
| 612 | git add file15 && |
| 613 | git commit -m "add initial versions" |
| 614 | ) |
| 615 | ) && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 616 | test_when_finished "rm -rf subdir/subdir_module" && |
Ævar Arnfjörð Bjarmason | 23fb328 | 2022-11-16 00:40:14 +0100 | [diff] [blame] | 617 | git submodule add file:///dev/null subdir/subdir_module && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 618 | git add subdir/subdir_module && |
| 619 | git commit -m "add submodule in subdirectory" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 620 | |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 621 | git checkout -b test$test_count.a test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 622 | git submodule update -N && |
| 623 | ( |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 624 | cd subdir/subdir_module && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 625 | git checkout -b super10.a && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 626 | echo test$test_count.a >file15 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 627 | git add file15 && |
| 628 | git commit -m "on branch 10.a" |
| 629 | ) && |
| 630 | git add subdir/subdir_module && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 631 | git commit -m "change submodule in subdirectory on test$test_count.a" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 632 | |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 633 | git checkout -b test$test_count.b test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 634 | git submodule update -N && |
| 635 | ( |
| 636 | cd subdir/subdir_module && |
| 637 | git checkout -b super10.b && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 638 | echo test$test_count.b >file15 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 639 | git add file15 && |
| 640 | git commit -m "on branch 10.b" |
| 641 | ) && |
| 642 | git add subdir/subdir_module && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 643 | git commit -m "change submodule in subdirectory on test$test_count.b" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 644 | |
Denton Liu | e9d309e | 2019-04-24 15:46:57 -0700 | [diff] [blame] | 645 | test_must_fail git merge test$test_count.a && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 646 | ( |
| 647 | cd subdir && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 648 | yes "l" | git mergetool subdir_module |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 649 | ) && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 650 | echo "test$test_count.b" >expect && |
| 651 | test_cmp expect subdir/subdir_module/file15 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 652 | git submodule update -N && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 653 | echo "test$test_count.b" >expect && |
| 654 | test_cmp expect subdir/subdir_module/file15 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 655 | git reset --hard && |
| 656 | git submodule update -N && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 657 | |
Denton Liu | e9d309e | 2019-04-24 15:46:57 -0700 | [diff] [blame] | 658 | test_must_fail git merge test$test_count.a && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 659 | yes "r" | git mergetool subdir/subdir_module && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 660 | echo "test$test_count.b" >expect && |
| 661 | test_cmp expect subdir/subdir_module/file15 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 662 | git submodule update -N && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 663 | echo "test$test_count.a" >expect && |
| 664 | test_cmp expect subdir/subdir_module/file15 && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 665 | git commit -m "branch1 resolved with mergetool" |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 666 | ' |
| 667 | |
| 668 | test_expect_success 'directory vs modified submodule' ' |
Richard Hansen | c3ad312 | 2017-01-10 15:41:55 -0500 | [diff] [blame] | 669 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 670 | git checkout -b test$test_count branch1 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 671 | mv submod submod-movedaside && |
| 672 | git rm --cached submod && |
| 673 | mkdir submod && |
| 674 | echo not a submodule >submod/file16 && |
| 675 | git add submod/file16 && |
| 676 | git commit -m "Submodule path becomes directory" && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 677 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 678 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 679 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 680 | yes "l" | git mergetool submod && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 681 | echo "not a submodule" >expect && |
| 682 | test_cmp expect submod/file16 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 683 | rm -rf submod.orig && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 684 | |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 685 | git reset --hard && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 686 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 687 | test -n "$(git ls-files -u)" && |
| 688 | test ! -e submod.orig && |
Elijah Newren | ef52778 | 2020-10-26 17:01:37 +0000 | [diff] [blame] | 689 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
| 690 | then |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 691 | yes "r" | git mergetool submod~main && |
Elijah Newren | ef52778 | 2020-10-26 17:01:37 +0000 | [diff] [blame] | 692 | git mv submod submod.orig && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 693 | git mv submod~main submod |
Elijah Newren | ef52778 | 2020-10-26 17:01:37 +0000 | [diff] [blame] | 694 | else |
| 695 | yes "r" | git mergetool submod |
| 696 | fi && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 697 | test -d submod.orig && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 698 | echo "not a submodule" >expect && |
| 699 | test_cmp expect submod.orig/file16 && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 700 | rm -r submod.orig && |
| 701 | mv submod-movedaside/.git submod && |
| 702 | ( cd submod && git clean -f && git reset --hard ) && |
| 703 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 704 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 705 | test_cmp expect submod/bar && |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 706 | git reset --hard && |
| 707 | rm -rf submod-movedaside && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 708 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 709 | git checkout -b test$test_count.c main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 710 | git submodule update -N && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 711 | test_must_fail git merge test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 712 | test -n "$(git ls-files -u)" && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 713 | yes "l" | git mergetool submod && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 714 | git submodule update -N && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 715 | echo "main submodule" >expect && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 716 | test_cmp expect submod/bar && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 717 | |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 718 | git reset --hard && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 719 | git submodule update -N && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 720 | test_must_fail git merge test$test_count && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 721 | test -n "$(git ls-files -u)" && |
| 722 | test ! -e submod.orig && |
Johannes Sixt | b4a04c8 | 2019-06-10 10:58:58 +0200 | [diff] [blame] | 723 | yes "r" | git mergetool submod && |
Johannes Sixt | e10dffd | 2019-06-12 18:33:46 +0200 | [diff] [blame] | 724 | echo "not a submodule" >expect && |
| 725 | test_cmp expect submod/file16 && |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 726 | |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 727 | git reset --hard main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 728 | ( cd submod && git clean -f && git reset --hard ) && |
| 729 | git submodule update -N |
Jonathon Mah | ff7f089 | 2011-04-13 03:00:48 -0700 | [diff] [blame] | 730 | ' |
| 731 | |
David Aguilar | ec245ba | 2012-01-19 23:47:35 -0800 | [diff] [blame] | 732 | test_expect_success 'file with no base' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 733 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 734 | git checkout -b test$test_count branch1 && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 735 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 736 | git mergetool --no-prompt --tool mybase -- both && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 737 | test_must_be_empty both |
David Aguilar | ec245ba | 2012-01-19 23:47:35 -0800 | [diff] [blame] | 738 | ' |
| 739 | |
David Aguilar | a427ef7 | 2012-09-25 00:48:11 -0700 | [diff] [blame] | 740 | test_expect_success 'custom commands override built-ins' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 741 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 742 | git checkout -b test$test_count branch1 && |
David Aguilar | f9e4308 | 2014-10-15 01:35:20 -0700 | [diff] [blame] | 743 | test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && |
| 744 | test_config mergetool.defaults.trustExitCode true && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 745 | test_must_fail git merge main && |
David Aguilar | 7457861 | 2014-10-15 01:35:17 -0700 | [diff] [blame] | 746 | git mergetool --no-prompt --tool defaults -- both && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 747 | echo main both added >expected && |
Stefan Beller | 9c5b2fa | 2017-10-06 12:00:06 -0700 | [diff] [blame] | 748 | test_cmp expected both |
David Aguilar | a427ef7 | 2012-09-25 00:48:11 -0700 | [diff] [blame] | 749 | ' |
| 750 | |
David Aguilar | 688684e | 2014-10-15 01:35:19 -0700 | [diff] [blame] | 751 | test_expect_success 'filenames seen by tools start with ./' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 752 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 753 | git checkout -b test$test_count branch1 && |
David Aguilar | 688684e | 2014-10-15 01:35:19 -0700 | [diff] [blame] | 754 | test_config mergetool.writeToTemp false && |
| 755 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && |
| 756 | test_config mergetool.myecho.trustExitCode true && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 757 | test_must_fail git merge main && |
David Aguilar | 688684e | 2014-10-15 01:35:19 -0700 | [diff] [blame] | 758 | git mergetool --no-prompt --tool myecho -- both >actual && |
Denton Liu | e9d309e | 2019-04-24 15:46:57 -0700 | [diff] [blame] | 759 | grep ^\./both_LOCAL_ actual |
David Aguilar | 688684e | 2014-10-15 01:35:19 -0700 | [diff] [blame] | 760 | ' |
| 761 | |
Armin Kunaschik | c578a09 | 2016-07-02 21:01:51 +0200 | [diff] [blame] | 762 | test_lazy_prereq MKTEMP ' |
| 763 | tempdir=$(mktemp -d -t foo.XXXXXX) && |
Jeff King | fa3142c | 2016-11-27 01:34:45 -0500 | [diff] [blame] | 764 | test -d "$tempdir" && |
| 765 | rmdir "$tempdir" |
Armin Kunaschik | c578a09 | 2016-07-02 21:01:51 +0200 | [diff] [blame] | 766 | ' |
| 767 | |
| 768 | test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 769 | test_when_finished "git reset --hard" && |
Richard Hansen | ecfdf0b | 2017-01-10 15:41:51 -0500 | [diff] [blame] | 770 | git checkout -b test$test_count branch1 && |
David Aguilar | 688684e | 2014-10-15 01:35:19 -0700 | [diff] [blame] | 771 | test_config mergetool.writeToTemp true && |
| 772 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && |
| 773 | test_config mergetool.myecho.trustExitCode true && |
Johannes Schindelin | 1e2ae14 | 2020-11-18 23:44:40 +0000 | [diff] [blame] | 774 | test_must_fail git merge main && |
David Aguilar | 688684e | 2014-10-15 01:35:19 -0700 | [diff] [blame] | 775 | git mergetool --no-prompt --tool myecho -- both >actual && |
Denton Liu | e9d309e | 2019-04-24 15:46:57 -0700 | [diff] [blame] | 776 | ! grep ^\./both_LOCAL_ actual && |
| 777 | grep /both_LOCAL_ actual |
David Aguilar | 688684e | 2014-10-15 01:35:19 -0700 | [diff] [blame] | 778 | ' |
| 779 | |
David Aguilar | 57937f7 | 2016-10-07 16:58:05 -0700 | [diff] [blame] | 780 | test_expect_success 'diff.orderFile configuration is honored' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 781 | test_when_finished "git reset --hard" && |
Richard Hansen | 61b76d2 | 2017-01-10 15:41:57 -0500 | [diff] [blame] | 782 | git checkout -b test$test_count order-file-side2 && |
David Aguilar | 57937f7 | 2016-10-07 16:58:05 -0700 | [diff] [blame] | 783 | test_config diff.orderFile order-file && |
| 784 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && |
| 785 | test_config mergetool.myecho.trustExitCode true && |
| 786 | echo b >order-file && |
| 787 | echo a >>order-file && |
David Aguilar | 57937f7 | 2016-10-07 16:58:05 -0700 | [diff] [blame] | 788 | test_must_fail git merge order-file-side1 && |
| 789 | cat >expect <<-\EOF && |
| 790 | Merging: |
| 791 | b |
| 792 | a |
| 793 | EOF |
Richard Hansen | d0e0cfe | 2017-01-10 15:42:02 -0500 | [diff] [blame] | 794 | |
| 795 | # make sure "order-file" that is ambiguous between |
| 796 | # rev and path is understood correctly. |
| 797 | git branch order-file HEAD && |
| 798 | |
David Aguilar | 57937f7 | 2016-10-07 16:58:05 -0700 | [diff] [blame] | 799 | git mergetool --no-prompt --tool myecho >output && |
| 800 | git grep --no-index -h -A2 Merging: output >actual && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 801 | test_cmp expect actual |
David Aguilar | 57937f7 | 2016-10-07 16:58:05 -0700 | [diff] [blame] | 802 | ' |
David Aguilar | 654311b | 2016-10-07 17:01:30 -0700 | [diff] [blame] | 803 | test_expect_success 'mergetool -Oorder-file is honored' ' |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 804 | test_when_finished "git reset --hard" && |
Richard Hansen | fef6c06 | 2017-01-10 15:41:58 -0500 | [diff] [blame] | 805 | git checkout -b test$test_count order-file-side2 && |
David Aguilar | 654311b | 2016-10-07 17:01:30 -0700 | [diff] [blame] | 806 | test_config diff.orderFile order-file && |
| 807 | test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && |
| 808 | test_config mergetool.myecho.trustExitCode true && |
Richard Hansen | b696ac9 | 2017-01-10 15:41:54 -0500 | [diff] [blame] | 809 | echo b >order-file && |
| 810 | echo a >>order-file && |
David Aguilar | 654311b | 2016-10-07 17:01:30 -0700 | [diff] [blame] | 811 | test_must_fail git merge order-file-side1 && |
| 812 | cat >expect <<-\EOF && |
| 813 | Merging: |
| 814 | a |
| 815 | b |
| 816 | EOF |
| 817 | git mergetool -O/dev/null --no-prompt --tool myecho >output && |
| 818 | git grep --no-index -h -A2 Merging: output >actual && |
| 819 | test_cmp expect actual && |
Richard Hansen | bd9714f | 2017-01-10 15:41:59 -0500 | [diff] [blame] | 820 | git reset --hard && |
David Aguilar | 654311b | 2016-10-07 17:01:30 -0700 | [diff] [blame] | 821 | |
| 822 | git config --unset diff.orderFile && |
| 823 | test_must_fail git merge order-file-side1 && |
| 824 | cat >expect <<-\EOF && |
| 825 | Merging: |
| 826 | b |
| 827 | a |
| 828 | EOF |
| 829 | git mergetool -Oorder-file --no-prompt --tool myecho >output && |
| 830 | git grep --no-index -h -A2 Merging: output >actual && |
Richard Hansen | 614eb27 | 2017-01-10 15:41:53 -0500 | [diff] [blame] | 831 | test_cmp expect actual |
David Aguilar | 654311b | 2016-10-07 17:01:30 -0700 | [diff] [blame] | 832 | ' |
David Aguilar | 57937f7 | 2016-10-07 16:58:05 -0700 | [diff] [blame] | 833 | |
Philippe Blain | 80f5a16 | 2021-01-07 01:09:05 +0000 | [diff] [blame] | 834 | test_expect_success 'mergetool --tool-help shows recognized tools' ' |
| 835 | # Check a few known tools are correctly shown |
| 836 | git mergetool --tool-help >mergetools && |
| 837 | grep vimdiff mergetools && |
| 838 | grep vimdiff3 mergetools && |
| 839 | grep gvimdiff2 mergetools && |
| 840 | grep araxis mergetools && |
| 841 | grep xxdiff mergetools && |
| 842 | grep meld mergetools |
| 843 | ' |
| 844 | |
Seth House | 98ea309 | 2021-02-09 13:07:10 -0700 | [diff] [blame] | 845 | test_expect_success 'mergetool hideResolved' ' |
| 846 | test_config mergetool.hideResolved true && |
| 847 | test_when_finished "git reset --hard" && |
Junio C Hamano | 78a26cb | 2021-02-17 17:21:41 -0800 | [diff] [blame] | 848 | git checkout -b test${test_count}_b main && |
Seth House | 98ea309 | 2021-02-09 13:07:10 -0700 | [diff] [blame] | 849 | test_write_lines >file1 base "" a && |
| 850 | git commit -a -m "base" && |
| 851 | test_write_lines >file1 base "" c && |
| 852 | git commit -a -m "remote update" && |
| 853 | git checkout -b test${test_count}_a HEAD~ && |
| 854 | test_write_lines >file1 local "" b && |
| 855 | git commit -a -m "local update" && |
| 856 | test_must_fail git merge test${test_count}_b && |
| 857 | yes "" | git mergetool file1 && |
| 858 | test_write_lines >expect local "" c && |
| 859 | test_cmp expect file1 && |
| 860 | git commit -m "test resolved with mergetool" |
| 861 | ' |
| 862 | |
Tao Klerks | 42943b9 | 2023-03-18 15:27:43 +0000 | [diff] [blame] | 863 | test_expect_success 'mergetool with guiDefault' ' |
| 864 | test_config merge.guitool myguitool && |
| 865 | test_config mergetool.myguitool.cmd "(printf \"gui \" && cat \"\$REMOTE\") >\"\$MERGED\"" && |
| 866 | test_config mergetool.myguitool.trustExitCode true && |
| 867 | test_when_finished "git reset --hard" && |
| 868 | git checkout -b test$test_count branch1 && |
| 869 | git submodule update -N && |
| 870 | test_must_fail git merge main && |
| 871 | |
| 872 | test_config mergetool.guiDefault auto && |
| 873 | DISPLAY=SOMETHING && export DISPLAY && |
| 874 | yes "" | git mergetool both && |
| 875 | yes "" | git mergetool file1 file1 && |
| 876 | |
| 877 | DISPLAY= && export DISPLAY && |
| 878 | yes "" | git mergetool file2 "spaced name" && |
| 879 | |
| 880 | test_config mergetool.guiDefault true && |
| 881 | yes "" | git mergetool subdir/file3 && |
| 882 | |
| 883 | yes "d" | git mergetool file11 && |
| 884 | yes "d" | git mergetool file12 && |
| 885 | yes "l" | git mergetool submod && |
| 886 | |
| 887 | echo "gui main updated" >expect && |
| 888 | test_cmp expect file1 && |
| 889 | |
| 890 | echo "main new" >expect && |
| 891 | test_cmp expect file2 && |
| 892 | |
| 893 | echo "gui main new sub" >expect && |
| 894 | test_cmp expect subdir/file3 && |
| 895 | |
| 896 | echo "branch1 submodule" >expect && |
| 897 | test_cmp expect submod/bar && |
| 898 | git commit -m "branch1 resolved with mergetool" |
| 899 | ' |
| 900 | |
Charles Bailey | 05e934b | 2008-02-21 23:31:56 +0000 | [diff] [blame] | 901 | test_done |