tests/test-backout.t
changeset 11856 db969ebdebd9
parent 8167 6c82beaaa11a
child 12316 4134686b83e1
equal deleted inserted replaced
11855:054b0d9c3f0c 11856:db969ebdebd9
       
     1   $ HGMERGE=true; export HGMERGE
       
     2 
       
     3   $ hg init basic
       
     4   $ cd basic
       
     5 
       
     6 # should complain
       
     7 
       
     8   $ hg backout
       
     9   abort: please specify a revision to backout
       
    10   $ hg backout -r 0 0
       
    11   abort: please specify just one revision
       
    12 
       
    13 # basic operation
       
    14 
       
    15   $ echo a > a
       
    16   $ hg commit -d '0 0' -A -m a
       
    17   adding a
       
    18   $ echo b >> a
       
    19   $ hg commit -d '1 0' -m b
       
    20 
       
    21   $ hg backout -d '2 0' tip
       
    22   reverting a
       
    23   changeset 2:2929462c3dff backs out changeset 1:a820f4f40a57
       
    24   $ cat a
       
    25   a
       
    26 
       
    27 # file that was removed is recreated
       
    28 
       
    29   $ cd ..
       
    30   $ hg init remove
       
    31   $ cd remove
       
    32 
       
    33   $ echo content > a
       
    34   $ hg commit -d '0 0' -A -m a
       
    35   adding a
       
    36 
       
    37   $ hg rm a
       
    38   $ hg commit -d '1 0' -m b
       
    39 
       
    40   $ hg backout -d '2 0' --merge tip
       
    41   adding a
       
    42   changeset 2:de31bdc76c0d backs out changeset 1:76862dcce372
       
    43   $ cat a
       
    44   content
       
    45 
       
    46 # backout of backout is as if nothing happened
       
    47 
       
    48   $ hg backout -d '3 0' --merge tip
       
    49   removing a
       
    50   changeset 3:7f6d0f120113 backs out changeset 2:de31bdc76c0d
       
    51   $ cat a 2>/dev/null || echo cat: a: No such file or directory
       
    52   cat: a: No such file or directory
       
    53 
       
    54 # across branch
       
    55 
       
    56   $ cd ..
       
    57   $ hg init branch
       
    58   $ cd branch
       
    59   $ echo a > a
       
    60   $ hg ci -Am0
       
    61   adding a
       
    62   $ echo b > b
       
    63   $ hg ci -Am1
       
    64   adding b
       
    65   $ hg co -C 0
       
    66   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
       
    67 
       
    68 should fail
       
    69 
       
    70   $ hg backout 1
       
    71   abort: cannot backout change on a different branch
       
    72   $ echo c > c
       
    73   $ hg ci -Am2
       
    74   adding c
       
    75   created new head
       
    76 
       
    77 should fail
       
    78 
       
    79   $ hg backout 1
       
    80   abort: cannot backout change on a different branch
       
    81 
       
    82 # backout with merge
       
    83 
       
    84   $ cd ..
       
    85   $ hg init merge
       
    86   $ cd merge
       
    87 
       
    88   $ echo line 1 > a
       
    89   $ echo line 2 >> a
       
    90   $ hg commit -d '0 0' -A -m a
       
    91   adding a
       
    92 
       
    93 remove line 1
       
    94 
       
    95   $ echo line 2 > a
       
    96   $ hg commit -d '1 0' -m b
       
    97 
       
    98   $ echo line 3 >> a
       
    99   $ hg commit -d '2 0' -m c
       
   100 
       
   101   $ hg backout --merge -d '3 0' 1
       
   102   reverting a
       
   103   created new head
       
   104   changeset 3:26b8ccb9ad91 backs out changeset 1:5a50a024c182
       
   105   merging with changeset 3:26b8ccb9ad91
       
   106   merging a
       
   107   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
       
   108   (branch merge, don't forget to commit)
       
   109   $ hg commit -d '4 0' -m d
       
   110 
       
   111 check line 1 is back
       
   112 
       
   113   $ cat a
       
   114   line 1
       
   115   line 2
       
   116   line 3
       
   117 
       
   118 # backout should not back out subsequent changesets
       
   119 
       
   120   $ hg init onecs
       
   121   $ cd onecs
       
   122   $ echo 1 > a
       
   123   $ hg commit -d '0 0' -A -m a
       
   124   adding a
       
   125   $ echo 2 >> a
       
   126   $ hg commit -d '1 0' -m b
       
   127   $ echo 1 > b
       
   128   $ hg commit -d '2 0' -A -m c
       
   129   adding b
       
   130   $ hg backout -d '3 0' 1
       
   131   reverting a
       
   132   created new head
       
   133   changeset 3:3202beb76721 backs out changeset 1:22bca4c721e5
       
   134   the backout changeset is a new head - do not forget to merge
       
   135   (use "backout --merge" if you want to auto-merge)
       
   136   $ hg locate b
       
   137   b
       
   138   $ hg update -C tip
       
   139   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
       
   140   $ hg locate b
       
   141 
       
   142   $ cd ..
       
   143   $ hg init m
       
   144   $ cd m
       
   145   $ echo a > a
       
   146   $ hg commit -d '0 0' -A -m a
       
   147   adding a
       
   148   $ echo b > b
       
   149   $ hg commit -d '1 0' -A -m b
       
   150   adding b
       
   151   $ echo c > c
       
   152   $ hg commit -d '2 0' -A -m b
       
   153   adding c
       
   154   $ hg update 1
       
   155   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
       
   156   $ echo d > d
       
   157   $ hg commit -d '3 0' -A -m c
       
   158   adding d
       
   159   created new head
       
   160   $ hg merge 2
       
   161   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
       
   162   (branch merge, don't forget to commit)
       
   163   $ hg commit -d '4 0' -A -m d
       
   164 
       
   165 # backout of merge should fail
       
   166 
       
   167   $ hg backout 4
       
   168   abort: cannot backout a merge changeset without --parent
       
   169 
       
   170 # backout of merge with bad parent should fail
       
   171 
       
   172   $ hg backout --parent 0 4
       
   173   abort: cb9a9f314b8b is not a parent of b2f3bb92043e
       
   174 
       
   175 # backout of non-merge with parent should fail
       
   176 
       
   177   $ hg backout --parent 0 3
       
   178   abort: cannot use --parent on non-merge changeset
       
   179 
       
   180 # backout with valid parent should be ok
       
   181 
       
   182   $ hg backout -d '5 0' --parent 2 4
       
   183   removing d
       
   184   changeset 5:10e5328c8435 backs out changeset 4:b2f3bb92043e
       
   185 
       
   186   $ hg rollback
       
   187   rolling back to revision 4 (undo commit)
       
   188   $ hg update -C
       
   189   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
       
   190 
       
   191   $ hg backout -d '6 0' --parent 3 4
       
   192   removing c
       
   193   changeset 5:033590168430 backs out changeset 4:b2f3bb92043e
       
   194 
       
   195   $ cd ..
       
   196 
       
   197 # named branches
       
   198 
       
   199   $ hg init named_branches
       
   200   $ cd named_branches
       
   201 
       
   202   $ echo default > default
       
   203   $ hg ci -d '0 0' -Am default
       
   204   adding default
       
   205   $ hg branch branch1
       
   206   marked working directory as branch branch1
       
   207   $ echo branch1 > file1
       
   208   $ hg ci -d '1 0' -Am file1
       
   209   adding file1
       
   210   $ hg branch branch2
       
   211   marked working directory as branch branch2
       
   212   $ echo branch2 > file2
       
   213   $ hg ci -d '2 0' -Am file2
       
   214   adding file2
       
   215   $ hg backout -d '3 0' -r 1 -m 'backout on branch1'
       
   216   removing file1
       
   217   created new head
       
   218   changeset 3:d4e8f6db59fb backs out changeset 1:bf1602f437f3
       
   219   the backout changeset is a new head - do not forget to merge
       
   220   (use "backout --merge" if you want to auto-merge)
       
   221 
       
   222 XXX maybe backout shouldn't suggest a merge here as it is a different branch?
       
   223 
       
   224 on branch2 with branch1 not merged, so file1 should still exist:
       
   225 
       
   226   $ hg id
       
   227   45bbcd363bf0 (branch2)
       
   228   $ hg st -A
       
   229   C default
       
   230   C file1
       
   231   C file2
       
   232 
       
   233 on branch2 with branch1 merged, so file1 should be gone:
       
   234 
       
   235   $ hg merge
       
   236   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
       
   237   (branch merge, don't forget to commit)
       
   238   $ hg ci -d '4 0' -m 'merge backout of branch1'
       
   239   $ hg id
       
   240   22149cdde76d (branch2) tip
       
   241   $ hg st -A
       
   242   C default
       
   243   C file2
       
   244 
       
   245 on branch1, so no file1 and file2:
       
   246 
       
   247   $ hg co -C branch1
       
   248   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
       
   249   $ hg id
       
   250   bf1602f437f3 (branch1)
       
   251   $ hg st -A
       
   252   C default
       
   253   C file1
       
   254 
       
   255   $ exit 0