Patchwork [v2] rebase: make sure merge state is cleaned up for no-op rebases

login
register
mail settings
Submitter Jeremy Fitzhardinge
Date May 16, 2017, 7:20 p.m.
Message ID <45e596670f05aba81f7c.1494962407@jsgf-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/20644/
State Accepted
Headers show

Comments

Jeremy Fitzhardinge - May 16, 2017, 7:20 p.m.
# HG changeset patch
# User Jeremy Fitzhardinge <jsgf@fb.com>
# Date 1494962309 25200
#      Tue May 16 12:18:29 2017 -0700
# Node ID 45e596670f05aba81f7caef7c778812028c7bc5a
# Parent  cb26d4cdd0f71423edde7451daf49f6f30bb385b
rebase: make sure merge state is cleaned up for no-op rebases

If a rebase ends up doing a no-op commit, make sure the merge state is still cleaned up.

Fix for issue5494.
Augie Fackler - May 16, 2017, 7:31 p.m.
On Tue, May 16, 2017 at 12:20:07PM -0700, Jeremy Fitzhardinge wrote:
> # HG changeset patch
> # User Jeremy Fitzhardinge <jsgf@fb.com>
> # Date 1494962309 25200
> #      Tue May 16 12:18:29 2017 -0700
> # Node ID 45e596670f05aba81f7caef7c778812028c7bc5a
> # Parent  cb26d4cdd0f71423edde7451daf49f6f30bb385b
> rebase: make sure merge state is cleaned up for no-op rebases

queued, thanks
Augie Fackler - May 17, 2017, 7:38 p.m.
On Tue, May 16, 2017 at 12:20:07PM -0700, Jeremy Fitzhardinge wrote:
> # HG changeset patch
> # User Jeremy Fitzhardinge <jsgf@fb.com>
> # Date 1494962309 25200
> #      Tue May 16 12:18:29 2017 -0700
> # Node ID 45e596670f05aba81f7caef7c778812028c7bc5a
> # Parent  cb26d4cdd0f71423edde7451daf49f6f30bb385b
> rebase: make sure merge state is cleaned up for no-op rebases
>
> If a rebase ends up doing a no-op commit, make sure the merge state is still cleaned up.
>
> Fix for issue5494.

Nit: this should be just (issue5494) on the summary line.

>
> diff --git a/hgext/rebase.py b/hgext/rebase.py
> --- a/hgext/rebase.py
> +++ b/hgext/rebase.py
> @@ -418,6 +418,11 @@
>                                             editor=editor,
>                                             keepbranches=self.keepbranchesf,
>                                             date=self.date)
> +                    if newnode is None:
> +                        # If it ended up being a no-op commit, then the normal
> +                        # merge state clean-up path doesn't happen, so do it here.
> +                        # Fix issue5494
> +                        mergemod.mergestate.clean(repo)
>                  else:
>                      # Skip commit if we are collapsing
>                      repo.dirstate.beginparentchange()
> diff --git a/tests/test-rebase-emptycleanup.t b/tests/test-rebase-emptycleanup.t
> new file mode 100644
> --- /dev/null
> +++ b/tests/test-rebase-emptycleanup.t

I'm -0 on the new test (it's likely one of the existing
test-rebase-*.t files could host this check?), but I've got a comment
below.

> @@ -0,0 +1,34 @@
> +  $ cat >> $HGRCPATH <<EOF

[...]

> +  $ hg resolve --list
> +  $ ls .hg/merge
> +  ls: .hg/merge: No such file or directory

On centos7, I get this:
-  ls: .hg/merge: No such file or directory
-  [1]
+  ls: cannot access .hg/merge: No such file or directory
+  [2]

So that's pretty great. Maybe use [ -e .hg/merge ] instead and just
use the exit code?

> +  [1]
> +
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -418,6 +418,11 @@ 
                                            editor=editor,
                                            keepbranches=self.keepbranchesf,
                                            date=self.date)
+                    if newnode is None:
+                        # If it ended up being a no-op commit, then the normal
+                        # merge state clean-up path doesn't happen, so do it here.
+                        # Fix issue5494
+                        mergemod.mergestate.clean(repo)
                 else:
                     # Skip commit if we are collapsing
                     repo.dirstate.beginparentchange()
diff --git a/tests/test-rebase-emptycleanup.t b/tests/test-rebase-emptycleanup.t
new file mode 100644
--- /dev/null
+++ b/tests/test-rebase-emptycleanup.t
@@ -0,0 +1,34 @@ 
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > rebase=
+  > EOF
+  $ hg init repo
+  $ cd repo
+  $ echo a >> a
+  $ hg commit -qAm base
+  $ echo b >> a
+  $ hg commit -qm b
+  $ hg up .^
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo c >> a
+  $ hg commit -qm c
+  $ hg rebase -s 1 -d 2 --noninteractive
+  rebasing 1:fdaca8533b86 "b"
+  merging a
+  warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see hg resolve, then hg rebase --continue)
+  [1]
+  $ echo a > a
+  $ echo c >> a
+  $ hg resolve --mark a
+  (no more unresolved files)
+  continue: hg rebase --continue
+  $ hg rebase --continue
+  rebasing 1:fdaca8533b86 "b"
+  note: rebase of 1:fdaca8533b86 created no changes to commit
+  saved backup bundle to $TESTTMP/repo/.hg/strip-backup/fdaca8533b86-7fd70513-backup.hg (glob)
+  $ hg resolve --list
+  $ ls .hg/merge
+  ls: .hg/merge: No such file or directory
+  [1]
+