3 test_description='git mv in subdirs'
 
   7     'prepare reference tree' \
 
   9      cp "$TEST_DIRECTORY"/../COPYING path0/COPYING &&
 
  10      git add path0/COPYING &&
 
  14     'moving the file out of subdirectory' \
 
  15     'cd path0 && git mv COPYING ../path1/COPYING'
 
  19     'commiting the change' \
 
  20     'cd .. && git commit -m move-out -a'
 
  23     'checking the commit' \
 
  24     'git diff-tree -r -M --name-status  HEAD^ HEAD | \
 
  25     grep "^R100..*path0/COPYING..*path1/COPYING"'
 
  28     'moving the file back into subdirectory' \
 
  29     'cd path0 && git mv ../path1/COPYING COPYING'
 
  33     'commiting the change' \
 
  34     'cd .. && git commit -m move-in -a'
 
  37     'checking the commit' \
 
  38     'git diff-tree -r -M --name-status  HEAD^ HEAD | \
 
  39     grep "^R100..*path1/COPYING..*path0/COPYING"'
 
  42     'checking -k on non-existing file' \
 
  43     'git mv -k idontexist path0'
 
  46     'checking -k on untracked file' \
 
  48      git mv -k untracked1 path0 &&
 
  50      test ! -f path0/untracked1'
 
  53     'checking -k on multiple untracked files' \
 
  55      git mv -k untracked1 untracked2 path0 &&
 
  58      test ! -f path0/untracked1 &&
 
  59      test ! -f path0/untracked2'
 
  62     'checking -f on untracked file with existing target' \
 
  63     'touch path0/untracked1 &&
 
  64      test_must_fail git mv -f untracked1 path0 &&
 
  65      test ! -f .git/index.lock &&
 
  67      test -f path0/untracked1'
 
  69 # clean up the mess in case bad things happen
 
  70 rm -f idontexist untracked1 untracked2 \
 
  71      path0/idontexist path0/untracked1 path0/untracked2 \
 
  75     'adding another file' \
 
  76     'cp "$TEST_DIRECTORY"/../README path0/README &&
 
  77      git add path0/README &&
 
  78      git commit -m add2 -a'
 
  81     'moving whole subdirectory' \
 
  85     'commiting the change' \
 
  86     'git commit -m dir-move -a'
 
  89     'checking the commit' \
 
  90     'git diff-tree -r -M --name-status  HEAD^ HEAD | \
 
  91      grep "^R100..*path0/COPYING..*path2/COPYING" &&
 
  92      git diff-tree -r -M --name-status  HEAD^ HEAD | \
 
  93      grep "^R100..*path0/README..*path2/README"'
 
  96     'succeed when source is a prefix of destination' \
 
  97     'git mv path2/COPYING path2/COPYING-renamed'
 
 100     'moving whole subdirectory into subdirectory' \
 
 103 test_expect_success \
 
 104     'commiting the change' \
 
 105     'git commit -m dir-move -a'
 
 107 test_expect_success \
 
 108     'checking the commit' \
 
 109     'git diff-tree -r -M --name-status  HEAD^ HEAD | \
 
 110      grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
 
 111      git diff-tree -r -M --name-status  HEAD^ HEAD | \
 
 112      grep "^R100..*path2/README..*path1/path2/README"'
 
 114 test_expect_success \
 
 115     'do not move directory over existing directory' \
 
 116     'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
 
 118 test_expect_success \
 
 120     'git mv path1/path2/ .'
 
 122 test_expect_success "Michael Cassar's test case" '
 
 123         rm -fr .git papers partA &&
 
 125         mkdir -p papers/unsorted papers/all-papers partA &&
 
 126         echo a > papers/unsorted/Thesis.pdf &&
 
 127         echo b > partA/outline.txt &&
 
 128         echo c > papers/unsorted/_another &&
 
 129         git add papers partA &&
 
 130         T1=`git write-tree` &&
 
 132         git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
 
 134         T=`git write-tree` &&
 
 135         git ls-tree -r $T | grep partA/outline.txt || {
 
 141 rm -fr papers partA path?
 
 143 test_expect_success "Sergey Vlasov's test case" '
 
 150         git commit -m 'initial' &&
 
 154 test_expect_success 'absolute pathname' '(
 
 159         test_create_repo one &&
 
 165         git mv sub "$(pwd)/in" &&
 
 168         git ls-files --error-unmatch in/file
 
 173 test_expect_success 'absolute pathname outside should fail' '(
 
 179         test_create_repo one &&
 
 185         test_must_fail git mv sub "$out/out" &&
 
 188         git ls-files --error-unmatch sub/file
 
 192 test_expect_success 'git mv to move multiple sources into a directory' '
 
 193         rm -fr .git && git init &&
 
 198         git mv dir/a.txt dir/b.txt other &&
 
 199         git ls-files >actual &&
 
 200         { echo other/a.txt; echo other/b.txt; } >expect &&
 
 201         test_cmp expect actual
 
 204 test_expect_success 'git mv should not change sha1 of moved cache entry' '
 
 210         entry="$(git ls-files --stage dirty | cut -f 1)" &&
 
 211         git mv dirty dirty2 &&
 
 212         [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
 
 214         git mv dirty2 dirty &&
 
 215         [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
 
 221 test_expect_success SYMLINKS 'git mv should overwrite symlink to a file' '
 
 226         ln -s moved symlink &&
 
 227         git add moved symlink &&
 
 228         test_must_fail git mv moved symlink &&
 
 229         git mv -f moved symlink &&
 
 232         test "$(cat symlink)" = 1 &&
 
 233         git update-index --refresh &&
 
 234         git diff-files --quiet
 
 240 test_expect_success SYMLINKS 'git mv should overwrite file with a symlink' '
 
 245         ln -s moved symlink &&
 
 246         git add moved symlink &&
 
 247         test_must_fail git mv symlink moved &&
 
 248         git mv -f symlink moved &&
 
 251         git update-index --refresh &&
 
 252         git diff-files --quiet