tests/test-rename
changeset 12098 12108d7f2ce1
parent 12097 389c215885c5
child 12099 54c9549ccb22
equal deleted inserted replaced
12097:389c215885c5 12098:12108d7f2ce1
     1 #!/bin/sh
       
     2 
       
     3 hg init
       
     4 mkdir d1 d1/d11 d2
       
     5 echo d1/a > d1/a
       
     6 echo d1/ba > d1/ba
       
     7 echo d1/a1 > d1/d11/a1
       
     8 echo d1/b > d1/b
       
     9 echo d2/b > d2/b
       
    10 hg add d1/a d1/b d1/ba d1/d11/a1 d2/b
       
    11 hg commit -m "1" -d "1000000 0"
       
    12 
       
    13 echo "# rename a single file"
       
    14 hg rename d1/d11/a1 d2/c
       
    15 hg sum
       
    16 hg status -C
       
    17 hg update -C
       
    18 rm d2/c
       
    19 
       
    20 echo "# rename --after a single file"
       
    21 mv d1/d11/a1 d2/c
       
    22 hg rename --after d1/d11/a1 d2/c
       
    23 hg status -C
       
    24 hg update -C
       
    25 rm d2/c
       
    26 
       
    27 echo '# rename --after a single file when src and tgt already tracked'
       
    28 mv d1/d11/a1 d2/c
       
    29 hg addrem -s 0
       
    30 hg rename --after d1/d11/a1 d2/c
       
    31 hg status -C
       
    32 hg update -C
       
    33 rm d2/c
       
    34 
       
    35 echo "# rename --after a single file to a nonexistant target filename"
       
    36 hg rename --after d1/a dummy
       
    37 
       
    38 echo "# move a single file to an existing directory"
       
    39 hg rename d1/d11/a1 d2
       
    40 hg status -C
       
    41 hg update -C
       
    42 rm d2/a1
       
    43 
       
    44 echo "# move --after a single file to an existing directory"
       
    45 mv d1/d11/a1 d2
       
    46 hg rename --after d1/d11/a1 d2
       
    47 hg status -C
       
    48 hg update -C
       
    49 rm d2/a1
       
    50 
       
    51 echo "# rename a file using a relative path"
       
    52 (cd d1/d11; hg rename ../../d2/b e)
       
    53 hg status -C
       
    54 hg update -C
       
    55 rm d1/d11/e
       
    56 
       
    57 echo "# rename --after a file using a relative path"
       
    58 (cd d1/d11; mv ../../d2/b e; hg rename --after ../../d2/b e)
       
    59 hg status -C
       
    60 hg update -C
       
    61 rm d1/d11/e
       
    62 
       
    63 echo "# rename directory d1 as d3"
       
    64 hg rename d1/ d3
       
    65 hg status -C
       
    66 hg update -C
       
    67 rm -rf d3
       
    68 
       
    69 echo "# rename --after directory d1 as d3"
       
    70 mv d1 d3
       
    71 hg rename --after d1 d3
       
    72 hg status -C
       
    73 hg update -C
       
    74 rm -rf d3
       
    75 
       
    76 echo "# move a directory using a relative path"
       
    77 (cd d2; mkdir d3; hg rename ../d1/d11 d3)
       
    78 hg status -C
       
    79 hg update -C
       
    80 rm -rf d2/d3
       
    81 
       
    82 echo "# move --after a directory using a relative path"
       
    83 (cd d2; mkdir d3; mv ../d1/d11 d3; hg rename --after ../d1/d11 d3)
       
    84 hg status -C
       
    85 hg update -C
       
    86 rm -rf d2/d3
       
    87 
       
    88 echo "# move directory d1/d11 to an existing directory d2 (removes empty d1)"
       
    89 hg rename d1/d11/ d2
       
    90 hg status -C
       
    91 hg update -C
       
    92 rm -rf d2/d11
       
    93 
       
    94 echo "# move directories d1 and d2 to a new directory d3"
       
    95 mkdir d3
       
    96 hg rename d1 d2 d3
       
    97 hg status -C
       
    98 hg update -C
       
    99 rm -rf d3
       
   100 
       
   101 echo "# move --after directories d1 and d2 to a new directory d3"
       
   102 mkdir d3
       
   103 mv d1 d2 d3
       
   104 hg rename --after d1 d2 d3
       
   105 hg status -C
       
   106 hg update -C
       
   107 rm -rf d3
       
   108 
       
   109 echo "# move everything under directory d1 to existing directory d2, do not"
       
   110 echo "# overwrite existing files (d2/b)"
       
   111 hg rename d1/* d2
       
   112 hg status -C
       
   113 diff d1/b d2/b
       
   114 hg update -C
       
   115 rm d2/a d2/ba d2/d11/a1
       
   116 
       
   117 echo "# attempt to move one file into a non-existent directory"
       
   118 hg rename d1/a dx/
       
   119 hg status -C
       
   120 hg update -C
       
   121 
       
   122 echo "# attempt to move potentially more than one file into a non-existent"
       
   123 echo "# directory"
       
   124 hg rename 'glob:d1/**' dx
       
   125 
       
   126 echo "# move every file under d1 to d2/d21 (glob)"
       
   127 mkdir d2/d21
       
   128 hg rename 'glob:d1/**' d2/d21
       
   129 hg status -C
       
   130 hg update -C
       
   131 rm -rf d2/d21
       
   132 
       
   133 echo "# move --after some files under d1 to d2/d21 (glob)"
       
   134 mkdir d2/d21
       
   135 mv d1/a d1/d11/a1 d2/d21
       
   136 hg rename --after 'glob:d1/**' d2/d21
       
   137 hg status -C
       
   138 hg update -C
       
   139 rm -rf d2/d21
       
   140 
       
   141 echo "# move every file under d1 starting with an 'a' to d2/d21 (regexp)"
       
   142 mkdir d2/d21
       
   143 hg rename 're:d1/([^a][^/]*/)*a.*' d2/d21
       
   144 hg status -C
       
   145 hg update -C
       
   146 rm -rf d2/d21
       
   147 
       
   148 echo "# attempt to overwrite an existing file"
       
   149 echo "ca" > d1/ca
       
   150 hg rename d1/ba d1/ca
       
   151 hg status -C
       
   152 hg update -C
       
   153 
       
   154 echo "# forced overwrite of an existing file"
       
   155 echo "ca" > d1/ca
       
   156 hg rename --force d1/ba d1/ca
       
   157 hg status -C
       
   158 hg update -C
       
   159 rm d1/ca
       
   160 
       
   161 echo "# replace a symlink with a file"
       
   162 ln -s ba d1/ca
       
   163 hg rename --force d1/ba d1/ca
       
   164 hg status -C
       
   165 hg update -C
       
   166 rm d1/ca
       
   167 
       
   168 echo "# do not copy more than one source file to the same destination file"
       
   169 mkdir d3
       
   170 hg rename d1/* d2/* d3
       
   171 hg status -C
       
   172 hg update -C
       
   173 rm -rf d3
       
   174 
       
   175 echo "# move a whole subtree with \"hg rename .\""
       
   176 mkdir d3
       
   177 (cd d1; hg rename . ../d3)
       
   178 hg status -C
       
   179 hg update -C
       
   180 rm -rf d3
       
   181 
       
   182 echo "# move a whole subtree with \"hg rename --after .\""
       
   183 mkdir d3
       
   184 mv d1/* d3
       
   185 (cd d1; hg rename --after . ../d3)
       
   186 hg status -C
       
   187 hg update -C
       
   188 rm -rf d3
       
   189 
       
   190 echo "# move the parent tree with \"hg rename ..\""
       
   191 (cd d1/d11; hg rename .. ../../d3)
       
   192 hg status -C
       
   193 hg update -C
       
   194 rm -rf d3
       
   195 
       
   196 echo "# skip removed files"
       
   197 hg remove d1/b
       
   198 hg rename d1 d3
       
   199 hg status -C
       
   200 hg update -C
       
   201 rm -rf d3
       
   202 
       
   203 echo "# transitive rename"
       
   204 hg rename d1/b d1/bb
       
   205 hg rename d1/bb d1/bc
       
   206 hg status -C
       
   207 hg update -C
       
   208 rm d1/bc
       
   209 
       
   210 echo "# transitive rename --after"
       
   211 hg rename d1/b d1/bb
       
   212 mv d1/bb d1/bc
       
   213 hg rename --after d1/bb d1/bc
       
   214 hg status -C
       
   215 hg update -C
       
   216 rm d1/bc
       
   217 
       
   218 echo "# idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b)"
       
   219 hg rename d1/b d1/bb
       
   220 echo "some stuff added to d1/bb" >> d1/bb
       
   221 hg rename d1/bb d1/b
       
   222 hg status -C
       
   223 hg update -C
       
   224 
       
   225 echo '# overwriting with renames (issue1959)'
       
   226 hg rename d1/a d1/c
       
   227 hg rename d1/b d1/a
       
   228 hg status -C
       
   229 hg diff --git
       
   230 hg update -C
       
   231 
       
   232 echo "# check illegal path components"
       
   233 
       
   234 hg rename d1/d11/a1 .hg/foo
       
   235 hg status -C
       
   236 hg rename d1/d11/a1 ../foo
       
   237 hg status -C
       
   238 
       
   239 mv d1/d11/a1 .hg/foo
       
   240 hg rename --after d1/d11/a1 .hg/foo
       
   241 hg status -C
       
   242 hg update -C
       
   243 rm .hg/foo
       
   244 
       
   245 hg rename d1/d11/a1 .hg
       
   246 hg status -C
       
   247 hg rename d1/d11/a1 ..
       
   248 hg status -C
       
   249 
       
   250 mv d1/d11/a1 .hg
       
   251 hg rename --after d1/d11/a1 .hg
       
   252 hg status -C
       
   253 hg update -C
       
   254 rm .hg/a1
       
   255 
       
   256 (cd d1/d11; hg rename ../../d2/b ../../.hg/foo)
       
   257 hg status -C
       
   258 (cd d1/d11; hg rename ../../d2/b ../../../foo)
       
   259 hg status -C
       
   260