# HG changeset patch # User Mark Thomas # Date 2018-10-12 17:48:40 # Node ID 31dfa7dac4c94f7a5de7580958c70b1391afe446 # Parent 9458dbfa7f339094c76fe7489132fc77e96beffe absorb: prompt user to accept absorb changes by default Change the default absorb behaviour to print the changes out and then prompt the user if they want to absorb the changes or not. Providing the `-p` option still prints the result and exits. A new `-a` option is provided which applies the changes without printing them, giving the equivalent of the old behaviour. Differential Revision: https://phab.mercurial-scm.org/D4999 diff --git a/hgext/absorb.py b/hgext/absorb.py --- a/hgext/absorb.py +++ b/hgext/absorb.py @@ -952,7 +952,7 @@ def absorb(ui, repo, stack=None, targetc chunks = cmdutil.recordfilter(ui, origchunks)[0] targetctx = overlaydiffcontext(stack[-1], chunks) fm = None - if opts.get('print_changes'): + if opts.get('print_changes') or not opts.get('apply_changes'): fm = ui.formatter('absorb', opts) state.diffwith(targetctx, matcher, fm) if fm is not None: @@ -971,6 +971,10 @@ def absorb(ui, repo, stack=None, targetc label='absorb.description') fm.end() if not opts.get('dry_run'): + if not opts.get('apply_changes'): + if ui.promptchoice("apply changes (yn)? $$ &Yes $$ &No", default=1): + raise error.Abort(_('absorb cancelled\n')) + state.apply() if state.commit(): state.printchunkstats() @@ -979,8 +983,10 @@ def absorb(ui, repo, stack=None, targetc return state @command('^absorb', - [('p', 'print-changes', None, - _('print which changesets are modified by which changes')), + [('a', 'apply-changes', None, + _('apply changes without prompting for confirmation')), + ('p', 'print-changes', None, + _('just print which changesets are modified by which changes')), ('i', 'interactive', None, _('interactively select which chunks to apply (EXPERIMENTAL)')), ('e', 'edit-lines', None, diff --git a/tests/test-absorb-edit-lines.t b/tests/test-absorb-edit-lines.t --- a/tests/test-absorb-edit-lines.t +++ b/tests/test-absorb-edit-lines.t @@ -15,10 +15,10 @@ Make some commits: absorb --edit-lines will run the editor if filename is provided: - $ hg absorb --edit-lines + $ hg absorb --edit-lines --apply-changes nothing applied [1] - $ HGEDITOR=cat hg absorb --edit-lines a + $ HGEDITOR=cat hg absorb --edit-lines --apply-changes a HG: editing a HG: "y" means the line to the right exists in the changeset to the top HG: @@ -43,7 +43,7 @@ Edit the file using --edit-lines: > y : f > yyy : g > EOF - $ HGEDITOR='cat editortext >' hg absorb -q --edit-lines a + $ HGEDITOR='cat editortext >' hg absorb -q --edit-lines --apply-changes a $ hg cat -r 0 a d e diff --git a/tests/test-absorb-phase.t b/tests/test-absorb-phase.t --- a/tests/test-absorb-phase.t +++ b/tests/test-absorb-phase.t @@ -19,7 +19,7 @@ $ hg update C -q $ printf B1 > B - $ hg absorb -q + $ hg absorb -aq $ hg log -G -T '{desc} {phase}' @ C secret diff --git a/tests/test-absorb-rename.t b/tests/test-absorb-rename.t --- a/tests/test-absorb-rename.t +++ b/tests/test-absorb-rename.t @@ -34,7 +34,7 @@ rename a to b, then b to a 2 0b888b00216c a: 3 $ sedi 's/$/a/' a - $ hg absorb -pq + $ hg absorb -apq showing changes for a @@ -0,3 +0,3 @@ eff892d -1 @@ -62,7 +62,7 @@ when the first changeset is public $ sedi 's/a/A/' a - $ hg absorb -pq + $ hg absorb -apq showing changes for a @@ -0,3 +0,3 @@ -1a @@ -105,7 +105,7 @@ copy a to b $ sedi 's/$/a/' a $ sedi 's/$/b/' b - $ hg absorb -pq + $ hg absorb -apq showing changes for a @@ -0,1 +0,1 @@ eff892d -1 @@ -149,7 +149,7 @@ copy b to a $ sedi 's/$/a/' a $ sedi 's/$/a/' b - $ hg absorb -pq + $ hg absorb -apq showing changes for a @@ -0,2 +0,2 @@ -1 @@ -196,7 +196,7 @@ copy b to a $ sedi 's/$/a/' a $ sedi 's/$/c/' c - $ hg absorb -pq + $ hg absorb -apq showing changes for a @@ -0,2 +0,2 @@ 55105f9 -1 @@ -244,7 +244,7 @@ copy b to a run absorb again would apply the change to c - $ hg absorb -pq + $ hg absorb -apq showing changes for c @@ -0,1 +0,1 @@ 7060601 -1 @@ -309,7 +309,7 @@ run absorb again would apply the change $ sedi 's/$/e/' e $ sedi 's/$/d/' d - $ hg absorb -pq + $ hg absorb -apq showing changes for d @@ -0,2 +0,2 @@ 55105f9 -1 diff --git a/tests/test-absorb-strip.t b/tests/test-absorb-strip.t --- a/tests/test-absorb-strip.t +++ b/tests/test-absorb-strip.t @@ -22,7 +22,7 @@ Do not strip innocent children. See http $ hg up E -q $ echo 1 >> B $ echo 2 >> D - $ hg absorb + $ hg absorb -a saved backup bundle to * (glob) 2 of 2 chunk(s) applied diff --git a/tests/test-absorb.t b/tests/test-absorb.t --- a/tests/test-absorb.t +++ b/tests/test-absorb.t @@ -68,7 +68,7 @@ Preview absorb changes: Run absorb: - $ hg absorb + $ hg absorb --apply-changes saved backup bundle to * (glob) 2 of 2 chunk(s) applied $ hg annotate a @@ -84,7 +84,20 @@ Delete a few lines and related commits w > 2b > 4d > EOF - $ hg absorb + $ echo y | hg absorb --config ui.interactive=1 + showing changes for a + @@ -0,1 +0,0 @@ + f548282 -1a + @@ -2,1 +1,0 @@ + ff5d556 -3 + @@ -4,1 +2,0 @@ + 84e5416 -5e + + 3 changesets affected + 84e5416 commit 5 + ff5d556 commit 3 + f548282 commit 1 + apply changes (yn)? y saved backup bundle to * (glob) 3 of 3 chunk(s) applied $ hg annotate a @@ -112,7 +125,7 @@ Delete a few lines and related commits w Non 1:1 map changes will be ignored: $ echo 1 > a - $ hg absorb + $ hg absorb --apply-changes nothing applied [1] @@ -124,7 +137,7 @@ Insertaions: > 4d > insert aftert 4d > EOF - $ hg absorb -q + $ hg absorb -q --apply-changes $ hg status $ hg annotate a 1: insert before 2b @@ -142,7 +155,7 @@ Bookmarks are moved: b2 2:946e4bc87915 * ba 2:946e4bc87915 $ sedi 's/insert/INSERT/' a - $ hg absorb -q + $ hg absorb -q --apply-changes $ hg status $ hg bookmarks b1 1:a4183e9b3d31 @@ -156,11 +169,11 @@ Non-mofified files are ignored: $ touch c $ hg add c $ hg rm b - $ hg absorb + $ hg absorb --apply-changes nothing applied [1] $ sedi 's/INSERT/Insert/' a - $ hg absorb + $ hg absorb --apply-changes saved backup bundle to * (glob) 2 of 2 chunk(s) applied $ hg status @@ -182,7 +195,7 @@ Public commits will not be changed: 1 changesets affected 85b4e0e commit 4 - $ hg absorb + $ hg absorb --apply-changes saved backup bundle to * (glob) 1 of 2 chunk(s) applied $ hg diff -U 0 @@ -233,7 +246,7 @@ Merge commit will not be changed: $ echo 2 >> m1 $ echo 2 >> m2 - $ hg absorb + $ hg absorb --apply-changes abort: no mutable changeset to change [255] $ hg revert -q -C m1 m2 @@ -259,15 +272,15 @@ Use pattern to select files to be fixed $ hg status M a M b - $ hg absorb a + $ hg absorb --apply-changes a saved backup bundle to * (glob) 1 of 1 chunk(s) applied $ hg status M b - $ hg absorb --exclude b + $ hg absorb --apply-changes --exclude b nothing applied [1] - $ hg absorb b + $ hg absorb --apply-changes b saved backup bundle to * (glob) 1 of 1 chunk(s) applied $ hg status @@ -312,7 +325,7 @@ Test obsolete markers creation: > add-noise=1 > EOF - $ hg --config absorb.max-stack-size=3 absorb + $ hg --config absorb.max-stack-size=3 absorb -a absorb: only the recent 3 changesets will be analysed 2 of 2 chunk(s) applied $ hg log -T '{rev}:{node|short} {desc} {get(extras, "absorb_source")}\n' @@ -320,7 +333,7 @@ Test obsolete markers creation: 5:99cfab7da5ff commit b 1 74cfa6294160149d60adbf7582b99ce37a4597ec 4:fec2b3bd9e08 commit a 2 28f10dcf96158f84985358a2e5d5b3505ca69c22 0:f9a81da8dc53 commit a 1 - $ hg absorb + $ hg absorb --apply-changes 1 of 1 chunk(s) applied $ hg log -T '{rev}:{node|short} {desc} {get(extras, "absorb_source")}\n' 10:e1c8c1e030a4 commit b 2 3dfde4199b4610ea6e3c6fa9f5bdad8939d69524 @@ -367,7 +380,7 @@ Executable files: 1 changesets affected 99b4ae7 foo - $ hg absorb + $ hg absorb --apply-changes 1 of 1 chunk(s) applied $ hg diff -c . diff --git a/foo.py b/foo.py @@ -414,7 +427,7 @@ Remove lines may delete changesets: 30970db b3 1154859 b12 bfafb49 a12 - $ hg absorb -v | grep became + $ hg absorb -av | grep became 0:bfafb49242db: 1 file(s) changed, became 4:1a2de97fc652 1:115485984805: 2 file(s) changed, became 5:0c930dfab74c 2:30970dbf7b40: became empty and was dropped @@ -468,7 +481,7 @@ This should move us to the non-obsolete 2 changesets affected 82dbe7f a1234 f1c23dd a123 - $ hg absorb --verbose + $ hg absorb --apply-changes --verbose 1:f1c23dd5d08d: became empty and was dropped 2:82dbe7fd19f0: became empty and was dropped a: 1 of 1 chunk(s) applied