backout: add --commit option
authorMateusz Kwapich <mitrandir@fb.com>
Wed, 17 Dec 2014 17:26:12 -0800
changeset 23615 7cfe58983bff
parent 23614 cd79fb4d75fd
child 23616 11a160547d7f
backout: add --commit option Mercurial backout command makes a commmit by default only when the backed out revision is the parent of working directory and doesn't commit in any other case. The --commit option changes behaviour of backout to make a commit whenever possible (i.e. there is no unresolved conflicts). This behaviour seems more intuitive to many use (especially git users migrating to hg).
mercurial/commands.py
tests/test-backout.t
tests/test-completion.t
--- a/mercurial/commands.py	Sat Dec 13 11:32:46 2014 -0800
+++ b/mercurial/commands.py	Wed Dec 17 17:26:12 2014 -0800
@@ -425,13 +425,14 @@
 
 @command('backout',
     [('', 'merge', None, _('merge with old dirstate parent after backout')),
+    ('', 'commit', None, _('commit if no conflicts were encountered')),
     ('', 'parent', '',
      _('parent to choose when backing out merge (DEPRECATED)'), _('REV')),
     ('r', 'rev', '', _('revision to backout'), _('REV')),
     ('e', 'edit', False, _('invoke editor on commit messages')),
     ] + mergetoolopts + walkopts + commitopts + commitopts2,
     _('[OPTION]... [-r] REV'))
-def backout(ui, repo, node=None, rev=None, **opts):
+def backout(ui, repo, node=None, rev=None, commit=False, **opts):
     '''reverse effect of earlier changeset
 
     Prepare a new changeset with the effect of REV undone in the
@@ -519,11 +520,12 @@
                 if stats[3]:
                     repo.ui.status(_("use 'hg resolve' to retry unresolved "
                                      "file merges\n"))
-                else:
+                    return 1
+                elif not commit:
                     msg = _("changeset %s backed out, "
                             "don't forget to commit.\n")
                     ui.status(msg % short(node))
-                return stats[3] > 0
+                    return 0
             finally:
                 ui.setconfig('ui', 'forcemerge', '', '')
         else:
--- a/tests/test-backout.t	Sat Dec 13 11:32:46 2014 -0800
+++ b/tests/test-backout.t	Wed Dec 17 17:26:12 2014 -0800
@@ -43,6 +43,47 @@
   commit: (clean)
   update: (current)
 
+commit option
+
+  $ cd ..
+  $ hg init commit
+  $ cd commit
+
+  $ echo tomatoes > a
+  $ hg add a
+  $ hg commit -d '0 0' -m tomatoes
+
+  $ echo chair > b
+  $ hg add b
+  $ hg commit -d '1 0' -m chair
+
+  $ echo grapes >> a
+  $ hg commit -d '2 0' -m grapes
+
+  $ hg backout --commit -d '4 0' 1 --tool=:fail
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  changeset 3:1c2161e97c0a backs out changeset 1:22cb4f70d813
+  $ hg summary
+  parent: 3:1c2161e97c0a tip
+   Backed out changeset 22cb4f70d813
+  branch: default
+  commit: (clean)
+  update: (current)
+
+  $ echo ypples > a
+  $ hg commit -d '5 0' -m ypples
+
+  $ hg backout --commit -d '6 0' 2 --tool=:fail
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges
+  [1]
+  $ hg summary
+  parent: 4:ed99997b793d tip
+   ypples
+  branch: default
+  commit: 1 unresolved (clean)
+  update: (current)
+
 file that was removed is recreated
 (this also tests that editor is not invoked if the commit message is
 specified explicitly)
--- a/tests/test-completion.t	Sat Dec 13 11:32:46 2014 -0800
+++ b/tests/test-completion.t	Wed Dec 17 17:26:12 2014 -0800
@@ -217,7 +217,7 @@
   update: clean, check, date, rev, tool
   addremove: similarity, subrepos, include, exclude, dry-run
   archive: no-decode, prefix, rev, type, subrepos, include, exclude
-  backout: merge, parent, rev, edit, tool, include, exclude, message, logfile, date, user
+  backout: merge, commit, parent, rev, edit, tool, include, exclude, message, logfile, date, user
   bisect: reset, good, bad, skip, extend, command, noupdate
   bookmarks: force, rev, delete, rename, inactive, template
   branch: force, clean