diff --git a/hgext3rd/fbamend/__init__.py b/hgext3rd/fbamend/__init__.py --- a/hgext3rd/fbamend/__init__.py +++ b/hgext3rd/fbamend/__init__.py @@ -184,6 +184,7 @@ def amend(ui, repo, *pats, **opts): '''amend the current changeset with more changes ''' + # 'rebase' is a tristate option: None=auto, True=force, False=disable rebase = opts.get('rebase') to = opts.get('to') @@ -263,6 +264,21 @@ ui.status(_("nothing changed\n")) return 1 + if haschildren and rebase is None and not _histediting(repo): + # If the user has chosen the default behaviour for the + # rebase, then see if we can apply any heuristics. This + # will not performed if a histedit is in flight. + + newcommit = repo[node] + # If the rebase did not change the manifest and the + # working copy is clean, force the children to be + # restacked. + if (old.manifestnode() == newcommit.manifestnode() and + not repo[None].dirty()): + ui.status(_('amend did not change the manifest, children ' + 'commits will be restacked automatically\n')) + rebase = True + if haschildren and not rebase: msg = _("warning: the changeset's children were left behind\n") if _histediting(repo): diff --git a/tests/test-fbamend-nextrebase.t b/tests/test-fbamend-nextrebase.t --- a/tests/test-fbamend-nextrebase.t +++ b/tests/test-fbamend-nextrebase.t @@ -35,7 +35,7 @@ $ hg debugbuilddag -n +4 $ hg up 1 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "amended" + $ hg amend -m "amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg next @@ -89,7 +89,7 @@ $ hg debugbuilddag -n +5 $ hg up 1 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "amended" + $ hg amend -m "amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg next --rebase --top @@ -115,7 +115,7 @@ $ hg debugbuilddag -n +5 $ hg up 1 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "amended" + $ hg amend -m "amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg next --rebase @@ -165,7 +165,7 @@ $ hg debugbuilddag -n +6 $ hg up 1 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "amended" + $ hg amend -m "amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg next --rebase 2 @@ -216,7 +216,7 @@ $ hg debugbuilddag -n +5 $ hg up 1 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "amend 1" + $ hg amend -m "amend 1" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg amend -m "amend 2" @@ -257,7 +257,7 @@ $ hg debugbuilddag -n +6 $ hg up 2 3 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "amended" + $ hg amend -m "amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg up 0 @@ -303,7 +303,7 @@ $ hg debugbuilddag -n +6 $ hg up 1 2 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "amended" + $ hg amend -m "amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ mkcommit a @@ -365,7 +365,7 @@ 0 files updated, 0 files merged, 2 files removed, 0 files unresolved $ echo "conflict" > c $ hg add c - $ hg amend -m "amended to add c" + $ hg amend -m "amended to add c" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ showgraph diff --git a/tests/test-fbamend-noinhibit.t b/tests/test-fbamend-noinhibit.t --- a/tests/test-fbamend-noinhibit.t +++ b/tests/test-fbamend-noinhibit.t @@ -12,7 +12,7 @@ $ hg debugbuilddag -m +3 $ hg update 1 1 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "Amended" + $ hg amend -m "Amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg rebase --restack diff --git a/tests/test-fbamend-restack.t b/tests/test-fbamend-restack.t --- a/tests/test-fbamend-restack.t +++ b/tests/test-fbamend-restack.t @@ -448,12 +448,12 @@ $ hg prev 0 files updated, 0 files merged, 1 files removed, 0 files unresolved [*] add b (glob) - $ hg amend -m "successor 1" + $ hg amend -m "successor 1" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg up 1 0 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "successor 2" + $ hg amend -m "successor 2" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg up 1 @@ -687,10 +687,10 @@ > A > EOS $ hg update B -q - $ hg commit --amend -m B2 -q 2>/dev/null + $ hg commit --amend -m B2 -q --no-rebase 2>/dev/null $ hg tag --local B2 $ hg rebase -r C -d B2 -q - $ hg commit --amend -m B3 -q 2>/dev/null + $ hg commit --amend -m B3 -q --no-rebase 2>/dev/null $ hg tag --local B3 $ showgraph @ 6 B3 @@ -867,3 +867,54 @@ | o 2 C |/ o 0 A + +Test auto-restack heuristics - no changes to manifest and clean working directory + $ reset + $ mkcommit a + $ mkcommit b + $ mkcommit c + $ hg prev + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + [7c3bad] add b + $ hg amend -m 'Unchanged manifest for b' + amend did not change the manifest, children commits will be restacked automatically + rebasing 2:4538525df7e2 "add c" + $ hg prev + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + [1f0dee] add a + $ hg amend -m 'Unchanged manifest for a' + amend did not change the manifest, children commits will be restacked automatically + rebasing 3:0024b613eb65 "Unchanged manifest for b" + rebasing 4:3fcb618bdf2b "add c" + +Test auto-restack heuristics - manifest changes + $ reset + $ mkcommit a + $ mkcommit b + $ mkcommit c + $ hg prev + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + [7c3bad] add b + $ echo 'new b' > b + $ hg amend -m 'Change manifest for b' + warning: the changeset's children were left behind + (use 'hg restack' to rebase them) + +Test auto-restack heuristics - no committed changes to manifest but dirty working directory + $ reset + $ mkcommit a + $ mkcommit b + $ mkcommit c + $ hg prev + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + [7c3bad] add b + $ echo 'new b' > b + $ hg amend a -m 'Unchanged manifest, but dirty workdir' + warning: the changeset's children were left behind + (use 'hg restack' to rebase them) + +Test auto-restack heuristics - no changes to manifest but no children + $ reset + $ mkcommit a + $ mkcommit b + $ hg amend -m 'Unchanged manifest for b' diff --git a/tests/test-fbamend-userestack.t b/tests/test-fbamend-userestack.t --- a/tests/test-fbamend-userestack.t +++ b/tests/test-fbamend-userestack.t @@ -35,7 +35,7 @@ $ mkcommit d $ hg up 1 0 files updated, 0 files merged, 2 files removed, 0 files unresolved - $ hg amend -m "amended" + $ hg amend -m "amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg book diff --git a/tests/test-smartlog-inhibit.t b/tests/test-smartlog-inhibit.t --- a/tests/test-smartlog-inhibit.t +++ b/tests/test-smartlog-inhibit.t @@ -15,7 +15,7 @@ $ hg book -r 3 test $ hg up 1 0 files updated, 0 files merged, 0 files removed, 0 files unresolved - $ hg amend -m "amended" + $ hg amend -m "amended" --no-rebase warning: the changeset's children were left behind (use 'hg restack' to rebase them) $ hg smartlog -T '{rev} {bookmarks}'