t / t7001-mv.shon commit filter-branch: Fix fatal error on bare repositories (9273b56)
   1#!/bin/sh
   2
   3test_description='git mv in subdirs'
   4. ./test-lib.sh
   5
   6test_expect_success \
   7    'prepare reference tree' \
   8    'mkdir path0 path1 &&
   9     cp "$TEST_DIRECTORY"/../COPYING path0/COPYING &&
  10     git add path0/COPYING &&
  11     git commit -m add -a'
  12
  13test_expect_success \
  14    'moving the file out of subdirectory' \
  15    'cd path0 && git mv COPYING ../path1/COPYING'
  16
  17# in path0 currently
  18test_expect_success \
  19    'commiting the change' \
  20    'cd .. && git commit -m move-out -a'
  21
  22test_expect_success \
  23    'checking the commit' \
  24    'git diff-tree -r -M --name-status  HEAD^ HEAD | \
  25    grep "^R100..*path0/COPYING..*path1/COPYING"'
  26
  27test_expect_success \
  28    'moving the file back into subdirectory' \
  29    'cd path0 && git mv ../path1/COPYING COPYING'
  30
  31# in path0 currently
  32test_expect_success \
  33    'commiting the change' \
  34    'cd .. && git commit -m move-in -a'
  35
  36test_expect_success \
  37    'checking the commit' \
  38    'git diff-tree -r -M --name-status  HEAD^ HEAD | \
  39    grep "^R100..*path1/COPYING..*path0/COPYING"'
  40
  41test_expect_success \
  42    'checking -k on non-existing file' \
  43    'git mv -k idontexist path0'
  44
  45test_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
  52test_expect_success \
  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 &&
  58     test ! -f path0/untracked1
  59     test ! -f path0/untracked2'
  60
  61# clean up the mess in case bad things happen
  62rm -f idontexist untracked1 untracked2 \
  63     path0/idontexist path0/untracked1 path0/untracked2 \
  64     .git/index.lock
  65
  66test_expect_success \
  67    'adding another file' \
  68    'cp "$TEST_DIRECTORY"/../README path0/README &&
  69     git add path0/README &&
  70     git commit -m add2 -a'
  71
  72test_expect_success \
  73    'moving whole subdirectory' \
  74    'git mv path0 path2'
  75
  76test_expect_success \
  77    'commiting the change' \
  78    'git commit -m dir-move -a'
  79
  80test_expect_success \
  81    'checking the commit' \
  82    'git diff-tree -r -M --name-status  HEAD^ HEAD | \
  83     grep "^R100..*path0/COPYING..*path2/COPYING" &&
  84     git diff-tree -r -M --name-status  HEAD^ HEAD | \
  85     grep "^R100..*path0/README..*path2/README"'
  86
  87test_expect_success \
  88    'succeed when source is a prefix of destination' \
  89    'git mv path2/COPYING path2/COPYING-renamed'
  90
  91test_expect_success \
  92    'moving whole subdirectory into subdirectory' \
  93    'git mv path2 path1'
  94
  95test_expect_success \
  96    'commiting the change' \
  97    'git commit -m dir-move -a'
  98
  99test_expect_success \
 100    'checking the commit' \
 101    'git diff-tree -r -M --name-status  HEAD^ HEAD | \
 102     grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
 103     git diff-tree -r -M --name-status  HEAD^ HEAD | \
 104     grep "^R100..*path2/README..*path1/path2/README"'
 105
 106test_expect_success \
 107    'do not move directory over existing directory' \
 108    'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
 109
 110test_expect_success \
 111    'move into "."' \
 112    'git mv path1/path2/ .'
 113
 114test_expect_success "Michael Cassar's test case" '
 115        rm -fr .git papers partA &&
 116        git init &&
 117        mkdir -p papers/unsorted papers/all-papers partA &&
 118        echo a > papers/unsorted/Thesis.pdf &&
 119        echo b > partA/outline.txt &&
 120        echo c > papers/unsorted/_another &&
 121        git add papers partA &&
 122        T1=`git write-tree` &&
 123
 124        git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
 125
 126        T=`git write-tree` &&
 127        git ls-tree -r $T | grep partA/outline.txt || {
 128                git ls-tree -r $T
 129                (exit 1)
 130        }
 131'
 132
 133rm -fr papers partA path?
 134
 135test_expect_success "Sergey Vlasov's test case" '
 136        rm -fr .git &&
 137        git init &&
 138        mkdir ab &&
 139        date >ab.c &&
 140        date >ab/d &&
 141        git add ab.c ab &&
 142        git commit -m 'initial' &&
 143        git mv ab a
 144'
 145
 146test_expect_success 'absolute pathname' '(
 147
 148        rm -fr mine &&
 149        mkdir mine &&
 150        cd mine &&
 151        test_create_repo one &&
 152        cd one &&
 153        mkdir sub &&
 154        >sub/file &&
 155        git add sub/file &&
 156
 157        git mv sub "$(pwd)/in" &&
 158        ! test -d sub &&
 159        test -d in &&
 160        git ls-files --error-unmatch in/file
 161
 162
 163)'
 164
 165test_expect_success 'absolute pathname outside should fail' '(
 166
 167        rm -fr mine &&
 168        mkdir mine &&
 169        cd mine &&
 170        out=$(pwd) &&
 171        test_create_repo one &&
 172        cd one &&
 173        mkdir sub &&
 174        >sub/file &&
 175        git add sub/file &&
 176
 177        test_must_fail git mv sub "$out/out" &&
 178        test -d sub &&
 179        ! test -d ../in &&
 180        git ls-files --error-unmatch sub/file
 181
 182)'
 183
 184test_expect_success 'git mv should not change sha1 of moved cache entry' '
 185
 186        rm -fr .git &&
 187        git init &&
 188        echo 1 >dirty &&
 189        git add dirty &&
 190        entry="$(git ls-files --stage dirty | cut -f 1)"
 191        git mv dirty dirty2 &&
 192        [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
 193        echo 2 >dirty2 &&
 194        git mv dirty2 dirty &&
 195        [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ]
 196
 197'
 198
 199rm -f dirty dirty2
 200
 201test_expect_success 'git mv should overwrite symlink to a file' '
 202
 203        rm -fr .git &&
 204        git init &&
 205        echo 1 >moved &&
 206        ln -s moved symlink &&
 207        git add moved symlink &&
 208        test_must_fail git mv moved symlink &&
 209        git mv -f moved symlink &&
 210        ! test -e moved &&
 211        test -f symlink &&
 212        test "$(cat symlink)" = 1 &&
 213        git update-index --refresh &&
 214        git diff-files --quiet
 215
 216'
 217
 218rm -f moved symlink
 219
 220test_expect_success 'git mv should overwrite file with a symlink' '
 221
 222        rm -fr .git &&
 223        git init &&
 224        echo 1 >moved &&
 225        ln -s moved symlink &&
 226        git add moved symlink &&
 227        test_must_fail git mv symlink moved &&
 228        git mv -f symlink moved &&
 229        ! test -e symlink &&
 230        test -h moved &&
 231        git update-index --refresh &&
 232        git diff-files --quiet
 233
 234'
 235
 236rm -f moved symlink
 237
 238test_done