Patchwork [2,of,2,STABLE] backout: correct commit status of no changes made (BC) (issue4190)

login
register
mail settings
Submitter Yuya Nishihara
Date March 8, 2014, 11:40 a.m.
Message ID <6e31f7ada8fa7df6496b.1394278812@gimlet>
Download mbox | patch
Permalink /patch/3890/
State Accepted
Commit 3f83fc5cfe715d292069ee8417c83804f6c6c1e4
Headers show

Comments

Yuya Nishihara - March 8, 2014, 11:40 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1394272336 -32400
#      Sat Mar 08 18:52:16 2014 +0900
# Branch stable
# Node ID 6e31f7ada8fa7df6496b6f6e7f3ccab641aa3f75
# Parent  734580066b4ec44a59cfe307ebc7999f9425c23b
backout: correct commit status of no changes made (BC) (issue4190)

If backout generated no changes to commit, it showed wrong status, "changeset
<target> backs out changeset <target>", and raised TypeError with -v option.

This changes the return code to 1, which is the same as "hg commit" and
"hg rebase".
Matt Mackall - April 1, 2014, 9:56 p.m.
On Sat, 2014-03-08 at 20:40 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1394272336 -32400
> #      Sat Mar 08 18:52:16 2014 +0900
> # Branch stable
> # Node ID 6e31f7ada8fa7df6496b6f6e7f3ccab641aa3f75
> # Parent  734580066b4ec44a59cfe307ebc7999f9425c23b
> backout: correct commit status of no changes made (BC) (issue4190)

These are queued for stable, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -416,7 +416,8 @@  def backout(ui, repo, node=None, rev=Non
 
     See :hg:`help dates` for a list of formats valid for -d/--date.
 
-    Returns 0 on success, 1 if there are unresolved files.
+    Returns 0 on success, 1 if nothing to backout or there are unresolved
+    files.
     '''
     if rev and node:
         raise util.Abort(_("please specify just one revision"))
@@ -495,6 +496,9 @@  def backout(ui, repo, node=None, rev=Non
             return repo.commit(message, opts.get('user'), opts.get('date'),
                                match, editor=e)
         newnode = cmdutil.commit(ui, repo, commitfunc, [], opts)
+        if not newnode:
+            ui.status(_("nothing changed\n"))
+            return 1
         cmdutil.commitstatus(repo, newnode, branch, bheads)
 
         def nice(node):
diff --git a/tests/test-backout.t b/tests/test-backout.t
--- a/tests/test-backout.t
+++ b/tests/test-backout.t
@@ -409,6 +409,22 @@  on branch1, so no file1 and file2:
 
   $ cd ..
 
+backout of empty changeset (issue4190)
+
+  $ hg init emptycommit
+  $ cd emptycommit
+
+  $ touch file1
+  $ hg ci -Aqm file1
+  $ hg branch -q branch1
+  $ hg ci -qm branch1
+  $ hg backout -v 1
+  resolving manifests
+  nothing changed
+  [1]
+
+  $ cd ..
+
 
 Test usage of `hg resolve` in case of conflict
 (issue4163)