tests/test-rename
changeset 8518 3f4f14eab085
parent 5329 7e6138cb8d38
child 10466 d1f209bb9564
equal deleted inserted replaced
8517:110763cc3ab0 8518:3f4f14eab085
    12 
    12 
    13 echo "# rename a single file"
    13 echo "# rename a single file"
    14 hg rename d1/d11/a1 d2/c
    14 hg rename d1/d11/a1 d2/c
    15 hg status -C
    15 hg status -C
    16 hg update -C
    16 hg update -C
       
    17 rm d2/c
    17 
    18 
    18 echo "# rename --after a single file"
    19 echo "# rename --after a single file"
    19 mv d1/d11/a1 d2/c
    20 mv d1/d11/a1 d2/c
    20 hg rename --after d1/d11/a1 d2/c
    21 hg rename --after d1/d11/a1 d2/c
    21 hg status -C
    22 hg status -C
    22 hg update -C
    23 hg update -C
       
    24 rm d2/c
    23 
    25 
    24 echo "# move a single file to an existing directory"
    26 echo "# move a single file to an existing directory"
    25 hg rename d1/d11/a1 d2
    27 hg rename d1/d11/a1 d2
    26 hg status -C
    28 hg status -C
    27 hg update -C
    29 hg update -C
       
    30 rm d2/a1
    28 
    31 
    29 echo "# move --after a single file to an existing directory"
    32 echo "# move --after a single file to an existing directory"
    30 mv d1/d11/a1 d2
    33 mv d1/d11/a1 d2
    31 hg rename --after d1/d11/a1 d2
    34 hg rename --after d1/d11/a1 d2
    32 hg status -C
    35 hg status -C
    33 hg update -C
    36 hg update -C
       
    37 rm d2/a1
    34 
    38 
    35 echo "# rename a file using a relative path"
    39 echo "# rename a file using a relative path"
    36 (cd d1/d11; hg rename ../../d2/b e)
    40 (cd d1/d11; hg rename ../../d2/b e)
    37 hg status -C
    41 hg status -C
    38 hg update -C
    42 hg update -C
       
    43 rm d1/d11/e
    39 
    44 
    40 echo "# rename --after a file using a relative path"
    45 echo "# rename --after a file using a relative path"
    41 (cd d1/d11; mv ../../d2/b e; hg rename --after ../../d2/b e)
    46 (cd d1/d11; mv ../../d2/b e; hg rename --after ../../d2/b e)
    42 hg status -C
    47 hg status -C
    43 hg update -C
    48 hg update -C
       
    49 rm d1/d11/e
    44 
    50 
    45 echo "# rename directory d1 as d3"
    51 echo "# rename directory d1 as d3"
    46 hg rename d1/ d3
    52 hg rename d1/ d3
    47 hg status -C
    53 hg status -C
    48 hg update -C
    54 hg update -C
       
    55 rm -rf d3
    49 
    56 
    50 echo "# rename --after directory d1 as d3"
    57 echo "# rename --after directory d1 as d3"
    51 mv d1 d3
    58 mv d1 d3
    52 hg rename --after d1 d3
    59 hg rename --after d1 d3
    53 hg status -C
    60 hg status -C
    54 hg update -C
    61 hg update -C
       
    62 rm -rf d3
    55 
    63 
    56 echo "# move a directory using a relative path"
    64 echo "# move a directory using a relative path"
    57 (cd d2; mkdir d3; hg rename ../d1/d11 d3)
    65 (cd d2; mkdir d3; hg rename ../d1/d11 d3)
    58 hg status -C
    66 hg status -C
    59 hg update -C
    67 hg update -C
       
    68 rm -rf d2/d3
    60 
    69 
    61 echo "# move --after a directory using a relative path"
    70 echo "# move --after a directory using a relative path"
    62 (cd d2; mkdir d3; mv ../d1/d11 d3; hg rename --after ../d1/d11 d3)
    71 (cd d2; mkdir d3; mv ../d1/d11 d3; hg rename --after ../d1/d11 d3)
    63 hg status -C
    72 hg status -C
    64 hg update -C
    73 hg update -C
       
    74 rm -rf d2/d3
    65 
    75 
    66 echo "# move directory d1/d11 to an existing directory d2 (removes empty d1)"
    76 echo "# move directory d1/d11 to an existing directory d2 (removes empty d1)"
    67 hg rename d1/d11/ d2
    77 hg rename d1/d11/ d2
    68 hg status -C
    78 hg status -C
    69 hg update -C
    79 hg update -C
       
    80 rm -rf d2/d11
    70 
    81 
    71 echo "# move directories d1 and d2 to a new directory d3"
    82 echo "# move directories d1 and d2 to a new directory d3"
    72 mkdir d3
    83 mkdir d3
    73 hg rename d1 d2 d3
    84 hg rename d1 d2 d3
    74 hg status -C
    85 hg status -C
    75 hg update -C
    86 hg update -C
       
    87 rm -rf d3
    76 
    88 
    77 echo "# move --after directories d1 and d2 to a new directory d3"
    89 echo "# move --after directories d1 and d2 to a new directory d3"
    78 mkdir d3
    90 mkdir d3
    79 mv d1 d2 d3
    91 mv d1 d2 d3
    80 hg rename --after d1 d2 d3
    92 hg rename --after d1 d2 d3
    81 hg status -C
    93 hg status -C
    82 hg update -C
    94 hg update -C
       
    95 rm -rf d3
    83 
    96 
    84 echo "# move everything under directory d1 to existing directory d2, do not"
    97 echo "# move everything under directory d1 to existing directory d2, do not"
    85 echo "# overwrite existing files (d2/b)"
    98 echo "# overwrite existing files (d2/b)"
    86 hg rename d1/* d2
    99 hg rename d1/* d2
    87 hg status -C
   100 hg status -C
    88 diff d1/b d2/b
   101 diff d1/b d2/b
    89 hg update -C
   102 hg update -C
       
   103 rm d2/a d2/ba d2/d11/a1
    90 
   104 
    91 echo "# attempt to move one file into a non-existent directory"
   105 echo "# attempt to move one file into a non-existent directory"
    92 hg rename d1/a dx/
   106 hg rename d1/a dx/
    93 hg status -C
   107 hg status -C
    94 hg update -C
   108 hg update -C
   100 echo "# move every file under d1 to d2/d21 (glob)"
   114 echo "# move every file under d1 to d2/d21 (glob)"
   101 mkdir d2/d21
   115 mkdir d2/d21
   102 hg rename 'glob:d1/**' d2/d21
   116 hg rename 'glob:d1/**' d2/d21
   103 hg status -C
   117 hg status -C
   104 hg update -C
   118 hg update -C
       
   119 rm -rf d2/d21
   105 
   120 
   106 echo "# move --after some files under d1 to d2/d21 (glob)"
   121 echo "# move --after some files under d1 to d2/d21 (glob)"
   107 mkdir d2/d21
   122 mkdir d2/d21
   108 mv d1/a d1/d11/a1 d2/d21
   123 mv d1/a d1/d11/a1 d2/d21
   109 hg rename --after 'glob:d1/**' d2/d21
   124 hg rename --after 'glob:d1/**' d2/d21
   110 hg status -C
   125 hg status -C
   111 hg update -C
   126 hg update -C
       
   127 rm -rf d2/d21
   112 
   128 
   113 echo "# move every file under d1 starting with an 'a' to d2/d21 (regexp)"
   129 echo "# move every file under d1 starting with an 'a' to d2/d21 (regexp)"
   114 mkdir d2/d21
   130 mkdir d2/d21
   115 hg rename 're:d1/([^a][^/]*/)*a.*' d2/d21
   131 hg rename 're:d1/([^a][^/]*/)*a.*' d2/d21
   116 hg status -C
   132 hg status -C
   117 hg update -C
   133 hg update -C
       
   134 rm -rf d2/d21
   118 
   135 
   119 echo "# attempt to overwrite an existing file"
   136 echo "# attempt to overwrite an existing file"
   120 echo "ca" > d1/ca
   137 echo "ca" > d1/ca
   121 hg rename d1/ba d1/ca
   138 hg rename d1/ba d1/ca
   122 hg status -C
   139 hg status -C
   125 echo "# forced overwrite of an existing file"
   142 echo "# forced overwrite of an existing file"
   126 echo "ca" > d1/ca
   143 echo "ca" > d1/ca
   127 hg rename --force d1/ba d1/ca
   144 hg rename --force d1/ba d1/ca
   128 hg status -C
   145 hg status -C
   129 hg update -C
   146 hg update -C
       
   147 rm d1/ca
   130 
   148 
   131 echo "# replace a symlink with a file"
   149 echo "# replace a symlink with a file"
   132 ln -s ba d1/ca
   150 ln -s ba d1/ca
   133 hg rename --force d1/ba d1/ca
   151 hg rename --force d1/ba d1/ca
   134 hg status -C
   152 hg status -C
   135 hg update -C
   153 hg update -C
       
   154 rm d1/ca
   136 
   155 
   137 echo "# do not copy more than one source file to the same destination file"
   156 echo "# do not copy more than one source file to the same destination file"
   138 mkdir d3
   157 mkdir d3
   139 hg rename d1/* d2/* d3
   158 hg rename d1/* d2/* d3
   140 hg status -C
   159 hg status -C
   141 hg update -C
   160 hg update -C
       
   161 rm -rf d3
   142 
   162 
   143 echo "# move a whole subtree with \"hg rename .\""
   163 echo "# move a whole subtree with \"hg rename .\""
   144 mkdir d3
   164 mkdir d3
   145 (cd d1; hg rename . ../d3)
   165 (cd d1; hg rename . ../d3)
   146 hg status -C
   166 hg status -C
   147 hg update -C
   167 hg update -C
       
   168 rm -rf d3
   148 
   169 
   149 echo "# move a whole subtree with \"hg rename --after .\""
   170 echo "# move a whole subtree with \"hg rename --after .\""
   150 mkdir d3
   171 mkdir d3
   151 mv d1/* d3
   172 mv d1/* d3
   152 (cd d1; hg rename --after . ../d3)
   173 (cd d1; hg rename --after . ../d3)
   153 hg status -C
   174 hg status -C
   154 hg update -C
   175 hg update -C
       
   176 rm -rf d3
   155 
   177 
   156 echo "# move the parent tree with \"hg rename ..\""
   178 echo "# move the parent tree with \"hg rename ..\""
   157 (cd d1/d11; hg rename .. ../../d3)
   179 (cd d1/d11; hg rename .. ../../d3)
   158 hg status -C
   180 hg status -C
   159 hg update -C
   181 hg update -C
       
   182 rm -rf d3
   160 
   183 
   161 echo "# skip removed files"
   184 echo "# skip removed files"
   162 hg remove d1/b
   185 hg remove d1/b
   163 hg rename d1 d3
   186 hg rename d1 d3
   164 hg status -C
   187 hg status -C
   165 hg update -C
   188 hg update -C
       
   189 rm -rf d3
   166 
   190 
   167 echo "# transitive rename"
   191 echo "# transitive rename"
   168 hg rename d1/b d1/bb
   192 hg rename d1/b d1/bb
   169 hg rename d1/bb d1/bc
   193 hg rename d1/bb d1/bc
   170 hg status -C
   194 hg status -C
   171 hg update -C
   195 hg update -C
       
   196 rm d1/bc
   172 
   197 
   173 echo "# transitive rename --after"
   198 echo "# transitive rename --after"
   174 hg rename d1/b d1/bb
   199 hg rename d1/b d1/bb
   175 mv d1/bb d1/bc
   200 mv d1/bb d1/bc
   176 hg rename --after d1/bb d1/bc
   201 hg rename --after d1/bb d1/bc
   177 hg status -C
   202 hg status -C
   178 hg update -C
   203 hg update -C
       
   204 rm d1/bc
   179 
   205 
   180 echo "# idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b)"
   206 echo "# idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b)"
   181 hg rename d1/b d1/bb
   207 hg rename d1/b d1/bb
   182 echo "some stuff added to d1/bb" >> d1/bb
   208 echo "some stuff added to d1/bb" >> d1/bb
   183 hg rename d1/bb d1/b
   209 hg rename d1/bb d1/b