changeset 40190:31dfa7dac4c9

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
author Mark Thomas <mbthomas@fb.com>
date Fri, 12 Oct 2018 17:48:40 +0000
parents 9458dbfa7f33
children 4b7eb862692e
files hgext/absorb.py tests/test-absorb-edit-lines.t tests/test-absorb-phase.t tests/test-absorb-rename.t tests/test-absorb-strip.t tests/test-absorb.t
diffstat 6 files changed, 51 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/absorb.py	Fri Oct 12 15:46:52 2018 +0000
+++ b/hgext/absorb.py	Fri Oct 12 17:48:40 2018 +0000
@@ -952,7 +952,7 @@
         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 @@
                      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 @@
     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,
--- a/tests/test-absorb-edit-lines.t	Fri Oct 12 15:46:52 2018 +0000
+++ b/tests/test-absorb-edit-lines.t	Fri Oct 12 17:48:40 2018 +0000
@@ -15,10 +15,10 @@
 
 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 @@
   >     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
--- a/tests/test-absorb-phase.t	Fri Oct 12 15:46:52 2018 +0000
+++ b/tests/test-absorb-phase.t	Fri Oct 12 17:48:40 2018 +0000
@@ -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
--- a/tests/test-absorb-rename.t	Fri Oct 12 15:46:52 2018 +0000
+++ b/tests/test-absorb-rename.t	Fri Oct 12 17:48:40 2018 +0000
@@ -34,7 +34,7 @@
   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 @@
 
   $ sedi 's/a/A/' a
 
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for a
           @@ -0,3 +0,3 @@
           -1a
@@ -105,7 +105,7 @@
   $ 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 @@
   $ 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 @@
   $ 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 @@
   
 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 @@
   $ sedi 's/$/e/' e
   $ sedi 's/$/d/' d
 
-  $ hg absorb -pq
+  $ hg absorb -apq
   showing changes for d
           @@ -0,2 +0,2 @@
   55105f9 -1
--- a/tests/test-absorb-strip.t	Fri Oct 12 15:46:52 2018 +0000
+++ b/tests/test-absorb-strip.t	Fri Oct 12 17:48:40 2018 +0000
@@ -22,7 +22,7 @@
   $ 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
 
--- a/tests/test-absorb.t	Fri Oct 12 15:46:52 2018 +0000
+++ b/tests/test-absorb.t	Fri Oct 12 17:48:40 2018 +0000
@@ -68,7 +68,7 @@
 
 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 @@
   > 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 @@
 Non 1:1 map changes will be ignored:
 
   $ echo 1 > a
-  $ hg absorb
+  $ hg absorb --apply-changes
   nothing applied
   [1]
 
@@ -124,7 +137,7 @@
   > 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 @@
      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 @@
   $ 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 @@
   
   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 @@
   
   $ 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 @@
   $ 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 @@
   > 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 @@
   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 @@
   
   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 @@
   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 @@
   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