Alex Riesen | 8bf2c69 | 2005-11-29 23:10:24 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 3 | test_description='git mv in subdirs' |
Alex Riesen | 8bf2c69 | 2005-11-29 23:10:24 +0100 | [diff] [blame] | 4 | . ./test-lib.sh |
| 5 | |
| 6 | test_expect_success \ |
| 7 | 'prepare reference tree' \ |
| 8 | 'mkdir path0 path1 && |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 9 | cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 10 | git add path0/COPYING && |
Nanako Shiraishi | d592b31 | 2008-09-03 17:59:31 +0900 | [diff] [blame] | 11 | git commit -m add -a' |
Alex Riesen | 8bf2c69 | 2005-11-29 23:10:24 +0100 | [diff] [blame] | 12 | |
| 13 | test_expect_success \ |
Josef Weidendorfer | 90924d5 | 2006-03-03 17:23:32 +0100 | [diff] [blame] | 14 | 'moving the file out of subdirectory' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 15 | 'cd path0 && git mv COPYING ../path1/COPYING' |
Alex Riesen | 8bf2c69 | 2005-11-29 23:10:24 +0100 | [diff] [blame] | 16 | |
| 17 | # in path0 currently |
| 18 | test_expect_success \ |
| 19 | 'commiting the change' \ |
Nanako Shiraishi | d592b31 | 2008-09-03 17:59:31 +0900 | [diff] [blame] | 20 | 'cd .. && git commit -m move-out -a' |
Alex Riesen | 8bf2c69 | 2005-11-29 23:10:24 +0100 | [diff] [blame] | 21 | |
| 22 | test_expect_success \ |
| 23 | 'checking the commit' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 24 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
Miklos Vajna | 90ed6c0 | 2008-01-05 05:06:48 +0100 | [diff] [blame] | 25 | grep "^R100..*path0/COPYING..*path1/COPYING"' |
Alex Riesen | 8bf2c69 | 2005-11-29 23:10:24 +0100 | [diff] [blame] | 26 | |
Josef Weidendorfer | 90924d5 | 2006-03-03 17:23:32 +0100 | [diff] [blame] | 27 | test_expect_success \ |
| 28 | 'moving the file back into subdirectory' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 29 | 'cd path0 && git mv ../path1/COPYING COPYING' |
Josef Weidendorfer | 90924d5 | 2006-03-03 17:23:32 +0100 | [diff] [blame] | 30 | |
| 31 | # in path0 currently |
| 32 | test_expect_success \ |
| 33 | 'commiting the change' \ |
Nanako Shiraishi | d592b31 | 2008-09-03 17:59:31 +0900 | [diff] [blame] | 34 | 'cd .. && git commit -m move-in -a' |
Josef Weidendorfer | 90924d5 | 2006-03-03 17:23:32 +0100 | [diff] [blame] | 35 | |
| 36 | test_expect_success \ |
| 37 | 'checking the commit' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 38 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
Miklos Vajna | 90ed6c0 | 2008-01-05 05:06:48 +0100 | [diff] [blame] | 39 | grep "^R100..*path1/COPYING..*path0/COPYING"' |
Josef Weidendorfer | 90924d5 | 2006-03-03 17:23:32 +0100 | [diff] [blame] | 40 | |
Josef Weidendorfer | afd2229 | 2006-07-26 15:44:08 +0200 | [diff] [blame] | 41 | test_expect_success \ |
Michael J Gruber | 3772923 | 2009-01-14 18:03:21 +0100 | [diff] [blame] | 42 | 'checking -k on non-existing file' \ |
| 43 | 'git mv -k idontexist path0' |
| 44 | |
| 45 | test_expect_success \ |
| 46 | 'checking -k on untracked file' \ |
| 47 | 'touch untracked1 && |
| 48 | git mv -k untracked1 path0 && |
| 49 | test -f untracked1 && |
| 50 | test ! -f path0/untracked1' |
| 51 | |
Michael J Gruber | be17262 | 2009-01-14 18:03:22 +0100 | [diff] [blame] | 52 | test_expect_success \ |
Michael J Gruber | 3772923 | 2009-01-14 18:03:21 +0100 | [diff] [blame] | 53 | 'checking -k on multiple untracked files' \ |
| 54 | 'touch untracked2 && |
| 55 | git mv -k untracked1 untracked2 path0 && |
| 56 | test -f untracked1 && |
| 57 | test -f untracked2 && |
Matthieu Moy | 720ec6b | 2009-02-04 10:32:06 +0100 | [diff] [blame] | 58 | test ! -f path0/untracked1 && |
Michael J Gruber | 3772923 | 2009-01-14 18:03:21 +0100 | [diff] [blame] | 59 | test ! -f path0/untracked2' |
| 60 | |
Matthieu Moy | 5aed3c6 | 2009-02-04 10:32:08 +0100 | [diff] [blame] | 61 | test_expect_success \ |
Matthieu Moy | c8ba6b1 | 2009-02-04 10:32:07 +0100 | [diff] [blame] | 62 | 'checking -f on untracked file with existing target' \ |
| 63 | 'touch path0/untracked1 && |
Elijah Newren | a2b1e53 | 2010-10-03 14:00:10 -0600 | [diff] [blame] | 64 | test_must_fail git mv -f untracked1 path0 && |
Matthieu Moy | c8ba6b1 | 2009-02-04 10:32:07 +0100 | [diff] [blame] | 65 | test ! -f .git/index.lock && |
| 66 | test -f untracked1 && |
| 67 | test -f path0/untracked1' |
| 68 | |
Michael J Gruber | 3772923 | 2009-01-14 18:03:21 +0100 | [diff] [blame] | 69 | # clean up the mess in case bad things happen |
| 70 | rm -f idontexist untracked1 untracked2 \ |
| 71 | path0/idontexist path0/untracked1 path0/untracked2 \ |
| 72 | .git/index.lock |
Matthieu Moy | c57f628 | 2013-12-03 09:32:04 +0100 | [diff] [blame] | 73 | rmdir path1 |
| 74 | |
| 75 | test_expect_success \ |
| 76 | 'moving to absent target with trailing slash' \ |
| 77 | 'test_must_fail git mv path0/COPYING no-such-dir/ && |
| 78 | test_must_fail git mv path0/COPYING no-such-dir// && |
| 79 | git mv path0/ no-such-dir/ && |
| 80 | test_path_is_dir no-such-dir' |
| 81 | |
| 82 | test_expect_success \ |
| 83 | 'clean up' \ |
| 84 | 'git reset --hard' |
| 85 | |
| 86 | test_expect_success \ |
| 87 | 'moving to existing untracked target with trailing slash' \ |
| 88 | 'mkdir path1 && |
| 89 | git mv path0/ path1/ && |
| 90 | test_path_is_dir path1/path0/' |
| 91 | |
| 92 | test_expect_success \ |
| 93 | 'moving to existing tracked target with trailing slash' \ |
| 94 | 'mkdir path2 && |
| 95 | >path2/file && git add path2/file && |
| 96 | git mv path1/path0/ path2/ && |
| 97 | test_path_is_dir path2/path0/' |
| 98 | |
| 99 | test_expect_success \ |
| 100 | 'clean up' \ |
| 101 | 'git reset --hard' |
Michael J Gruber | 3772923 | 2009-01-14 18:03:21 +0100 | [diff] [blame] | 102 | |
| 103 | test_expect_success \ |
Josef Weidendorfer | afd2229 | 2006-07-26 15:44:08 +0200 | [diff] [blame] | 104 | 'adding another file' \ |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 105 | 'cp "$TEST_DIRECTORY"/../README path0/README && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 106 | git add path0/README && |
Nanako Shiraishi | d592b31 | 2008-09-03 17:59:31 +0900 | [diff] [blame] | 107 | git commit -m add2 -a' |
Josef Weidendorfer | afd2229 | 2006-07-26 15:44:08 +0200 | [diff] [blame] | 108 | |
| 109 | test_expect_success \ |
| 110 | 'moving whole subdirectory' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 111 | 'git mv path0 path2' |
Josef Weidendorfer | afd2229 | 2006-07-26 15:44:08 +0200 | [diff] [blame] | 112 | |
| 113 | test_expect_success \ |
| 114 | 'commiting the change' \ |
Nanako Shiraishi | d592b31 | 2008-09-03 17:59:31 +0900 | [diff] [blame] | 115 | 'git commit -m dir-move -a' |
Josef Weidendorfer | afd2229 | 2006-07-26 15:44:08 +0200 | [diff] [blame] | 116 | |
| 117 | test_expect_success \ |
| 118 | 'checking the commit' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 119 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
Miklos Vajna | 90ed6c0 | 2008-01-05 05:06:48 +0100 | [diff] [blame] | 120 | grep "^R100..*path0/COPYING..*path2/COPYING" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 121 | git diff-tree -r -M --name-status HEAD^ HEAD | \ |
Miklos Vajna | 90ed6c0 | 2008-01-05 05:06:48 +0100 | [diff] [blame] | 122 | grep "^R100..*path0/README..*path2/README"' |
Josef Weidendorfer | afd2229 | 2006-07-26 15:44:08 +0200 | [diff] [blame] | 123 | |
Johannes Schindelin | a1dad60 | 2006-07-26 19:41:05 +0200 | [diff] [blame] | 124 | test_expect_success \ |
Johannes Schindelin | 1d6249e | 2006-08-16 02:20:32 +0200 | [diff] [blame] | 125 | 'succeed when source is a prefix of destination' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 126 | 'git mv path2/COPYING path2/COPYING-renamed' |
Johannes Schindelin | 1d6249e | 2006-08-16 02:20:32 +0200 | [diff] [blame] | 127 | |
| 128 | test_expect_success \ |
Johannes Schindelin | a1dad60 | 2006-07-26 19:41:05 +0200 | [diff] [blame] | 129 | 'moving whole subdirectory into subdirectory' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 130 | 'git mv path2 path1' |
Johannes Schindelin | a1dad60 | 2006-07-26 19:41:05 +0200 | [diff] [blame] | 131 | |
| 132 | test_expect_success \ |
| 133 | 'commiting the change' \ |
Nanako Shiraishi | d592b31 | 2008-09-03 17:59:31 +0900 | [diff] [blame] | 134 | 'git commit -m dir-move -a' |
Johannes Schindelin | a1dad60 | 2006-07-26 19:41:05 +0200 | [diff] [blame] | 135 | |
| 136 | test_expect_success \ |
| 137 | 'checking the commit' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 138 | 'git diff-tree -r -M --name-status HEAD^ HEAD | \ |
Miklos Vajna | 90ed6c0 | 2008-01-05 05:06:48 +0100 | [diff] [blame] | 139 | grep "^R100..*path2/COPYING..*path1/path2/COPYING" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 140 | git diff-tree -r -M --name-status HEAD^ HEAD | \ |
Miklos Vajna | 90ed6c0 | 2008-01-05 05:06:48 +0100 | [diff] [blame] | 141 | grep "^R100..*path2/README..*path1/path2/README"' |
Johannes Schindelin | a1dad60 | 2006-07-26 19:41:05 +0200 | [diff] [blame] | 142 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 143 | test_expect_success \ |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 144 | 'do not move directory over existing directory' \ |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 145 | 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0' |
Johannes Schindelin | ac64a72 | 2006-07-26 19:47:54 +0200 | [diff] [blame] | 146 | |
Johannes Schindelin | c5203bd | 2006-08-18 12:42:39 +0200 | [diff] [blame] | 147 | test_expect_success \ |
| 148 | 'move into "."' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 149 | 'git mv path1/path2/ .' |
Johannes Schindelin | c5203bd | 2006-08-18 12:42:39 +0200 | [diff] [blame] | 150 | |
Junio C Hamano | 4fddf57 | 2006-10-01 22:22:07 -0700 | [diff] [blame] | 151 | test_expect_success "Michael Cassar's test case" ' |
| 152 | rm -fr .git papers partA && |
Nicolas Pitre | 5c94f87 | 2007-01-12 16:01:46 -0500 | [diff] [blame] | 153 | git init && |
Junio C Hamano | 4fddf57 | 2006-10-01 22:22:07 -0700 | [diff] [blame] | 154 | mkdir -p papers/unsorted papers/all-papers partA && |
| 155 | echo a > papers/unsorted/Thesis.pdf && |
| 156 | echo b > partA/outline.txt && |
| 157 | echo c > papers/unsorted/_another && |
| 158 | git add papers partA && |
| 159 | T1=`git write-tree` && |
| 160 | |
| 161 | git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf && |
| 162 | |
| 163 | T=`git write-tree` && |
Jeff King | a167ece | 2015-03-20 06:09:00 -0400 | [diff] [blame] | 164 | git ls-tree -r $T | verbose grep partA/outline.txt |
Junio C Hamano | 4fddf57 | 2006-10-01 22:22:07 -0700 | [diff] [blame] | 165 | ' |
| 166 | |
Johannes Schindelin | aca085e | 2006-12-03 20:42:47 +0100 | [diff] [blame] | 167 | rm -fr papers partA path? |
| 168 | |
| 169 | test_expect_success "Sergey Vlasov's test case" ' |
| 170 | rm -fr .git && |
Nicolas Pitre | 5c94f87 | 2007-01-12 16:01:46 -0500 | [diff] [blame] | 171 | git init && |
Johannes Schindelin | aca085e | 2006-12-03 20:42:47 +0100 | [diff] [blame] | 172 | mkdir ab && |
| 173 | date >ab.c && |
| 174 | date >ab/d && |
| 175 | git add ab.c ab && |
| 176 | git commit -m 'initial' && |
| 177 | git mv ab a |
| 178 | ' |
| 179 | |
Junio C Hamano | 744dacd | 2008-02-03 23:59:17 -0800 | [diff] [blame] | 180 | test_expect_success 'absolute pathname' '( |
| 181 | |
| 182 | rm -fr mine && |
| 183 | mkdir mine && |
| 184 | cd mine && |
| 185 | test_create_repo one && |
| 186 | cd one && |
| 187 | mkdir sub && |
| 188 | >sub/file && |
| 189 | git add sub/file && |
| 190 | |
| 191 | git mv sub "$(pwd)/in" && |
| 192 | ! test -d sub && |
| 193 | test -d in && |
| 194 | git ls-files --error-unmatch in/file |
| 195 | |
| 196 | |
| 197 | )' |
| 198 | |
| 199 | test_expect_success 'absolute pathname outside should fail' '( |
| 200 | |
| 201 | rm -fr mine && |
| 202 | mkdir mine && |
| 203 | cd mine && |
| 204 | out=$(pwd) && |
| 205 | test_create_repo one && |
| 206 | cd one && |
| 207 | mkdir sub && |
| 208 | >sub/file && |
| 209 | git add sub/file && |
| 210 | |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 211 | test_must_fail git mv sub "$out/out" && |
Junio C Hamano | 744dacd | 2008-02-03 23:59:17 -0800 | [diff] [blame] | 212 | test -d sub && |
| 213 | ! test -d ../in && |
| 214 | git ls-files --error-unmatch sub/file |
| 215 | |
| 216 | )' |
| 217 | |
Junio C Hamano | af82559 | 2010-01-22 14:17:06 -0800 | [diff] [blame] | 218 | test_expect_success 'git mv to move multiple sources into a directory' ' |
| 219 | rm -fr .git && git init && |
| 220 | mkdir dir other && |
| 221 | >dir/a.txt && |
| 222 | >dir/b.txt && |
| 223 | git add dir/?.txt && |
| 224 | git mv dir/a.txt dir/b.txt other && |
| 225 | git ls-files >actual && |
| 226 | { echo other/a.txt; echo other/b.txt; } >expect && |
| 227 | test_cmp expect actual |
| 228 | ' |
| 229 | |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 230 | test_expect_success 'git mv should not change sha1 of moved cache entry' ' |
| 231 | |
| 232 | rm -fr .git && |
| 233 | git init && |
| 234 | echo 1 >dirty && |
| 235 | git add dirty && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 236 | entry="$(git ls-files --stage dirty | cut -f 1)" && |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 237 | git mv dirty dirty2 && |
| 238 | [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] && |
| 239 | echo 2 >dirty2 && |
| 240 | git mv dirty2 dirty && |
| 241 | [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ] |
| 242 | |
| 243 | ' |
| 244 | |
| 245 | rm -f dirty dirty2 |
| 246 | |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 247 | test_expect_success 'git mv should overwrite symlink to a file' ' |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 248 | |
| 249 | rm -fr .git && |
| 250 | git init && |
| 251 | echo 1 >moved && |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 252 | test_ln_s_add moved symlink && |
| 253 | git add moved && |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 254 | test_must_fail git mv moved symlink && |
| 255 | git mv -f moved symlink && |
| 256 | ! test -e moved && |
| 257 | test -f symlink && |
| 258 | test "$(cat symlink)" = 1 && |
Junio C Hamano | 65c35b2 | 2008-07-28 22:27:39 -0700 | [diff] [blame] | 259 | git update-index --refresh && |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 260 | git diff-files --quiet |
| 261 | |
| 262 | ' |
| 263 | |
| 264 | rm -f moved symlink |
| 265 | |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 266 | test_expect_success 'git mv should overwrite file with a symlink' ' |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 267 | |
| 268 | rm -fr .git && |
| 269 | git init && |
| 270 | echo 1 >moved && |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 271 | test_ln_s_add moved symlink && |
| 272 | git add moved && |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 273 | test_must_fail git mv symlink moved && |
| 274 | git mv -f symlink moved && |
| 275 | ! test -e symlink && |
Junio C Hamano | 65c35b2 | 2008-07-28 22:27:39 -0700 | [diff] [blame] | 276 | git update-index --refresh && |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 277 | git diff-files --quiet |
| 278 | |
| 279 | ' |
| 280 | |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 281 | test_expect_success SYMLINKS 'check moved symlink' ' |
| 282 | |
| 283 | test -h moved |
| 284 | ' |
| 285 | |
Petr Baudis | 81dc230 | 2008-07-21 02:25:56 +0200 | [diff] [blame] | 286 | rm -f moved symlink |
| 287 | |
Jens Lehmann | 1150246 | 2013-07-30 21:49:25 +0200 | [diff] [blame] | 288 | test_expect_success 'setup submodule' ' |
| 289 | git commit -m initial && |
| 290 | git reset --hard && |
| 291 | git submodule add ./. sub && |
| 292 | echo content >file && |
| 293 | git add file && |
brian m. carlson | fb8a4e8 | 2014-03-15 18:56:52 +0000 | [diff] [blame] | 294 | git commit -m "added sub and file" && |
| 295 | git branch submodule |
Jens Lehmann | 1150246 | 2013-07-30 21:49:25 +0200 | [diff] [blame] | 296 | ' |
| 297 | |
| 298 | test_expect_success 'git mv cannot move a submodule in a file' ' |
| 299 | test_must_fail git mv sub file |
| 300 | ' |
| 301 | |
| 302 | test_expect_success 'git mv moves a submodule with a .git directory and no .gitmodules' ' |
| 303 | entry="$(git ls-files --stage sub | cut -f 1)" && |
| 304 | git rm .gitmodules && |
| 305 | ( |
| 306 | cd sub && |
| 307 | rm -f .git && |
Kyle J. McKay | 00764ca | 2014-04-11 01:24:02 -0700 | [diff] [blame] | 308 | cp -R -P -p ../.git/modules/sub .git && |
Jens Lehmann | 1150246 | 2013-07-30 21:49:25 +0200 | [diff] [blame] | 309 | GIT_WORK_TREE=. git config --unset core.worktree |
| 310 | ) && |
| 311 | mkdir mod && |
| 312 | git mv sub mod/sub && |
| 313 | ! test -e sub && |
| 314 | [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && |
| 315 | ( |
| 316 | cd mod/sub && |
| 317 | git status |
| 318 | ) && |
| 319 | git update-index --refresh && |
| 320 | git diff-files --quiet |
| 321 | ' |
| 322 | |
Jens Lehmann | 04c1ee5 | 2013-10-13 13:52:05 +0200 | [diff] [blame] | 323 | test_expect_success 'git mv moves a submodule with a .git directory and .gitmodules' ' |
| 324 | rm -rf mod && |
| 325 | git reset --hard && |
| 326 | git submodule update && |
| 327 | entry="$(git ls-files --stage sub | cut -f 1)" && |
| 328 | ( |
| 329 | cd sub && |
| 330 | rm -f .git && |
Kyle J. McKay | 00764ca | 2014-04-11 01:24:02 -0700 | [diff] [blame] | 331 | cp -R -P -p ../.git/modules/sub .git && |
Jens Lehmann | 04c1ee5 | 2013-10-13 13:52:05 +0200 | [diff] [blame] | 332 | GIT_WORK_TREE=. git config --unset core.worktree |
| 333 | ) && |
| 334 | mkdir mod && |
| 335 | git mv sub mod/sub && |
| 336 | ! test -e sub && |
| 337 | [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && |
| 338 | ( |
| 339 | cd mod/sub && |
| 340 | git status |
| 341 | ) && |
| 342 | echo mod/sub >expected && |
| 343 | git config -f .gitmodules submodule.sub.path >actual && |
| 344 | test_cmp expected actual && |
| 345 | git update-index --refresh && |
| 346 | git diff-files --quiet |
| 347 | ' |
| 348 | |
Jens Lehmann | a88c915 | 2013-07-30 21:50:03 +0200 | [diff] [blame] | 349 | test_expect_success 'git mv moves a submodule with gitfile' ' |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 350 | rm -rf mod && |
Jens Lehmann | a88c915 | 2013-07-30 21:50:03 +0200 | [diff] [blame] | 351 | git reset --hard && |
| 352 | git submodule update && |
| 353 | entry="$(git ls-files --stage sub | cut -f 1)" && |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 354 | mkdir mod && |
Jens Lehmann | a88c915 | 2013-07-30 21:50:03 +0200 | [diff] [blame] | 355 | ( |
| 356 | cd mod && |
| 357 | git mv ../sub/ . |
| 358 | ) && |
| 359 | ! test -e sub && |
| 360 | [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && |
| 361 | ( |
| 362 | cd mod/sub && |
| 363 | git status |
| 364 | ) && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 365 | echo mod/sub >expected && |
| 366 | git config -f .gitmodules submodule.sub.path >actual && |
| 367 | test_cmp expected actual && |
Jens Lehmann | a88c915 | 2013-07-30 21:50:03 +0200 | [diff] [blame] | 368 | git update-index --refresh && |
| 369 | git diff-files --quiet |
| 370 | ' |
| 371 | |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 372 | test_expect_success 'mv does not complain when no .gitmodules file is found' ' |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 373 | rm -rf mod && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 374 | git reset --hard && |
| 375 | git submodule update && |
| 376 | git rm .gitmodules && |
| 377 | entry="$(git ls-files --stage sub | cut -f 1)" && |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 378 | mkdir mod && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 379 | git mv sub mod/sub 2>actual.err && |
| 380 | ! test -s actual.err && |
| 381 | ! test -e sub && |
| 382 | [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && |
| 383 | ( |
| 384 | cd mod/sub && |
| 385 | git status |
| 386 | ) && |
| 387 | git update-index --refresh && |
| 388 | git diff-files --quiet |
| 389 | ' |
| 390 | |
| 391 | test_expect_success 'mv will error out on a modified .gitmodules file unless staged' ' |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 392 | rm -rf mod && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 393 | git reset --hard && |
| 394 | git submodule update && |
| 395 | git config -f .gitmodules foo.bar true && |
| 396 | entry="$(git ls-files --stage sub | cut -f 1)" && |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 397 | mkdir mod && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 398 | test_must_fail git mv sub mod/sub 2>actual.err && |
| 399 | test -s actual.err && |
| 400 | test -e sub && |
| 401 | git diff-files --quiet -- sub && |
| 402 | git add .gitmodules && |
| 403 | git mv sub mod/sub 2>actual.err && |
| 404 | ! test -s actual.err && |
| 405 | ! test -e sub && |
| 406 | [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && |
| 407 | ( |
| 408 | cd mod/sub && |
| 409 | git status |
| 410 | ) && |
| 411 | git update-index --refresh && |
| 412 | git diff-files --quiet |
| 413 | ' |
| 414 | |
| 415 | test_expect_success 'mv issues a warning when section is not found in .gitmodules' ' |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 416 | rm -rf mod && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 417 | git reset --hard && |
| 418 | git submodule update && |
| 419 | git config -f .gitmodules --remove-section submodule.sub && |
| 420 | git add .gitmodules && |
| 421 | entry="$(git ls-files --stage sub | cut -f 1)" && |
| 422 | echo "warning: Could not find section in .gitmodules where path=sub" >expect.err && |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 423 | mkdir mod && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 424 | git mv sub mod/sub 2>actual.err && |
| 425 | test_i18ncmp expect.err actual.err && |
| 426 | ! test -e sub && |
| 427 | [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && |
| 428 | ( |
| 429 | cd mod/sub && |
| 430 | git status |
| 431 | ) && |
| 432 | git update-index --refresh && |
| 433 | git diff-files --quiet |
| 434 | ' |
| 435 | |
| 436 | test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' ' |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 437 | rm -rf mod && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 438 | git reset --hard && |
| 439 | git submodule update && |
Jonathan Nieder | 2b2b1e4 | 2014-09-10 14:01:46 -0700 | [diff] [blame] | 440 | mkdir mod && |
Jens Lehmann | 0656781 | 2013-08-06 21:15:11 +0200 | [diff] [blame] | 441 | git mv -n sub mod/sub 2>actual.err && |
| 442 | test -f sub/.git && |
| 443 | git diff-index --exit-code HEAD && |
| 444 | git update-index --refresh && |
| 445 | git diff-files --quiet -- sub .gitmodules |
| 446 | ' |
| 447 | |
Jens Lehmann | 1cbd183 | 2014-01-07 22:31:32 +0100 | [diff] [blame] | 448 | test_expect_success 'checking out a commit before submodule moved needs manual updates' ' |
| 449 | git mv sub sub2 && |
| 450 | git commit -m "moved sub to sub2" && |
| 451 | git checkout -q HEAD^ 2>actual && |
Charles Bailey | 11b5390 | 2014-03-29 15:39:01 +0000 | [diff] [blame] | 452 | test_i18ngrep "^warning: unable to rmdir sub2:" actual && |
Jens Lehmann | 1cbd183 | 2014-01-07 22:31:32 +0100 | [diff] [blame] | 453 | git status -s sub2 >actual && |
| 454 | echo "?? sub2/" >expected && |
| 455 | test_cmp expected actual && |
| 456 | ! test -f sub/.git && |
| 457 | test -f sub2/.git && |
| 458 | git submodule update && |
| 459 | test -f sub/.git && |
| 460 | rm -rf sub2 && |
| 461 | git diff-index --exit-code HEAD && |
| 462 | git update-index --refresh && |
| 463 | git diff-files --quiet -- sub .gitmodules && |
| 464 | git status -s sub2 >actual && |
| 465 | ! test -s actual |
| 466 | ' |
| 467 | |
brian m. carlson | fb8a4e8 | 2014-03-15 18:56:52 +0000 | [diff] [blame] | 468 | test_expect_success 'mv -k does not accidentally destroy submodules' ' |
| 469 | git checkout submodule && |
| 470 | mkdir dummy dest && |
| 471 | git mv -k dummy sub dest && |
| 472 | git status --porcelain >actual && |
| 473 | grep "^R sub -> dest/sub" actual && |
| 474 | git reset --hard && |
| 475 | git checkout . |
| 476 | ' |
| 477 | |
Alex Riesen | 8bf2c69 | 2005-11-29 23:10:24 +0100 | [diff] [blame] | 478 | test_done |