Follow upstream changes -- rest
[git-darcs-import.git] / tests / mv-formerly-pl.sh
blobf64861a53b76bda0aa89c1964b2f339b4f61fed8
1 #!/usr/bin/env bash
2 set -ev
4 # Some tests for 'darcs mv'
6 ## I would use the builtin !, but that has the wrong semantics.
7 not () { "$@" && exit 1 || :; }
9 # darcs does not support cygwin paths (/cygdrive/c/foo), so if
10 # we want to run the test suite under Cygwin Bash, we must
11 # convert accordingly
12 portable_pwd () {
13 if uname | grep -i cygwin > /dev/null; then
14 cygpath -w `pwd`
15 else
16 pwd
20 rm -rf temp
21 mkdir temp
22 cd temp
23 darcs init
25 ###
27 echo adding a directory with more than one .. in it should work.
28 mkdir foo.d
29 mkdir foo.d/second
30 mkdir foo.d/second/third
31 mkdir foo.d/other
34 touch ./foo.d/other/date.t
35 darcs add -r foo.d
37 cd foo.d/second/third
39 darcs mv ../../other/date.t ../../other/date_moved.t
41 cd ../../..
42 echo darcs refuses to move to an existing file
43 touch ping
44 touch pong
45 darcs add ping pong
46 not darcs mv ping pong &> out
47 cat out
48 grep 'already exists' out
50 # case sensitivity series
51 # -----------------------
52 # these are tests designed to check out darcs behave wrt to renames
53 # where the case of the file becomes important
55 # are we on a case sensitive file system?
56 touch is_it_cs
57 rm -f IS_IT_CS
59 if test -e is_it_cs; then
60 echo This is a case-sensitive file system.
61 else
62 echo This is NOT a case-sensitive file system.
65 # if the new file already exists - we don't allow it
66 # basically the same test as mv ping pong, except we do mv ping PING
67 # and both ping and PING exist on the filesystem
68 echo "case sensitivity - simply don't allow mv if new file exists"
69 touch 'cs-n-1'; touch 'CS-N-1';
70 touch 'cs-y-1'; touch 'CS-Y-1';
71 darcs add cs-n-1 cs-y-1
73 if test -e is_it_cs; then
74 # regardless of case-ok, we do NOT want this mv at all
75 not darcs mv cs-n-1 CS-Y-1 &> out
76 cat out
77 grep 'already exists' out
79 not darcs mv --case-ok cs-n-1 CS-Y-1 &> out
80 cat out
81 grep 'already exists' out
84 # if the new file does not already exist - we allow it
85 echo "case sensitivity - the new file does *not* exist"
86 touch 'cs-n-2';
87 touch 'cs-y-2';
88 darcs add cs-n-2 cs-y-2
89 # these mv's should be allowed regardless of flag or filesystem
90 darcs mv cs-n-2 CS-N-2
91 darcs mv --case-ok cs-y-2 CS-Y-2
93 # parasites - do not accidentally overwrite a file just because it has a
94 # similar name and points to the same inode. We want to check if a file if the
95 # same NAME already exists - we shouldn't care about what the actual file is!
96 echo "case sensitivity - inode check";
97 touch 'cs-n-3';
98 touch 'cs-y-3';
99 darcs add cs-n-3 cs-y-3
101 if ln cs-n-3 CS-N-3; then # checking if we support hard links
102 ln cs-y-3 CS-Y-3
103 # regardless of case-ok, we do NOT want this mv at all
104 not darcs mv cs-n-3 CS-N-3 &> out
105 cat out
106 grep 'already exists' out
108 not darcs mv --case-ok cs-y-3 CS-Y-3 &> out
109 cat out
110 grep 'already exists' out
113 # parasites - we don't allow weird stuff like mv foo bar/foo just because
114 # we opened up some crazy exception based on foo's name
115 echo 'refuses to move to an existing file with same name, different path'
116 touch 'cs-n-4'; touch 'foo.d/cs-n-4';
117 touch 'cs-y-4'; touch 'foo.d/cs-y-4';
118 darcs add cs-n-4
119 # regardless of case-ok, we do NOT want this mv at all
120 not darcs mv cs-n-4 foo.d/cs-n-4 &> out
121 cat out
122 grep 'already exists' out
124 not darcs mv --case-ok cs-y-4 foo.d/cs-y-4 &> out
125 cat out
126 grep 'already exists' out
128 # ---------------------------
129 # end case sensitivity series
131 touch abs_path.t
132 darcs add abs_path.t
133 IFS=""
134 REPO_ABS=`portable_pwd`
135 darcs mv "$REPO_ABS/abs_path.t" abs_path_new.t
136 darcs mv abs_path_new.t "$REPO_ABS/abs_path.t"
139 # issue608
141 touch 'gonna_be_deleted';
142 darcs add gonna_be_deleted
143 darcs record -am 'added doomed file'
144 rm gonna_be_deleted
145 darcs record -am 'deleted file'
146 touch 'new_file';
147 darcs add new_file
148 darcs mv new_file gonna_be_deleted