Code

revision traversal: allow UNINTERESTING objects to be missing
[git.git] / t / t7001-mv.sh
1 #!/bin/sh
3 test_description='git mv in subdirs'
4 . ./test-lib.sh
6 test_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'
13 test_expect_success \
14     'moving the file out of subdirectory' \
15     'cd path0 && git mv COPYING ../path1/COPYING'
17 # in path0 currently
18 test_expect_success \
19     'commiting the change' \
20     'cd .. && git commit -m move-out -a'
22 test_expect_success \
23     'checking the commit' \
24     'git diff-tree -r -M --name-status  HEAD^ HEAD | \
25     grep "^R100..*path0/COPYING..*path1/COPYING"'
27 test_expect_success \
28     'moving the file back into subdirectory' \
29     'cd path0 && git mv ../path1/COPYING COPYING'
31 # in path0 currently
32 test_expect_success \
33     'commiting the change' \
34     'cd .. && git commit -m move-in -a'
36 test_expect_success \
37     'checking the commit' \
38     'git diff-tree -r -M --name-status  HEAD^ HEAD | \
39     grep "^R100..*path1/COPYING..*path0/COPYING"'
41 test_expect_success \
42     'checking -k on non-existing file' \
43     'git mv -k idontexist path0'
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'
52 test_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'
61 # clean up the mess in case bad things happen
62 rm -f idontexist untracked1 untracked2 \
63      path0/idontexist path0/untracked1 path0/untracked2 \
64      .git/index.lock
66 test_expect_success \
67     'adding another file' \
68     'cp "$TEST_DIRECTORY"/../README path0/README &&
69      git add path0/README &&
70      git commit -m add2 -a'
72 test_expect_success \
73     'moving whole subdirectory' \
74     'git mv path0 path2'
76 test_expect_success \
77     'commiting the change' \
78     'git commit -m dir-move -a'
80 test_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"'
87 test_expect_success \
88     'succeed when source is a prefix of destination' \
89     'git mv path2/COPYING path2/COPYING-renamed'
91 test_expect_success \
92     'moving whole subdirectory into subdirectory' \
93     'git mv path2 path1'
95 test_expect_success \
96     'commiting the change' \
97     'git commit -m dir-move -a'
99 test_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"'
106 test_expect_success \
107     'do not move directory over existing directory' \
108     'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0'
110 test_expect_success \
111     'move into "."' \
112     'git mv path1/path2/ .'
114 test_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` &&
124         git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
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         }
133 rm -fr papers partA path?
135 test_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
146 test_expect_success 'absolute pathname' '(
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 &&
157         git mv sub "$(pwd)/in" &&
158         ! test -d sub &&
159         test -d in &&
160         git ls-files --error-unmatch in/file
163 )'
165 test_expect_success 'absolute pathname outside should fail' '(
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 &&
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
182 )'
184 test_expect_success 'git mv should not change sha1 of moved cache entry' '
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)" ]
199 rm -f dirty dirty2
201 test_expect_success 'git mv should overwrite symlink to a file' '
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
218 rm -f moved symlink
220 test_expect_success 'git mv should overwrite file with a symlink' '
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
236 rm -f moved symlink
238 test_done