comparison tests/test-revert-interactive.t @ 41987:c1d83d916e85

revert: option to choose what to keep, not what to discard I know the you (the reader) are probably tired of discussing how `hg revert -i -r .` should behave and so am I. And I know I'm one of the people who argued that showing the diff from the working copy to the parent was confusing. I think it is less confusing now that we show the diff from the parent to the working copy, but I still find it confusing. I think showing the diff of hunks to keep might make it easier to understand. So that's what this patch provides an option for. One argument doing it this way is that most people seem to find `hg split` natural. I suspect that is because it shows the forward diff (from parent commit to the commit) and asks you what to put in the first commit. I think the new "keep" mode for revert (this patch) matches that. In "keep" mode, all the changes are still selected by default. That means that `hg revert -i` followed by 'A' (keep all) (or 'c' in curses) will be different from `hg revert -a`. That's mostly because that was simplest. It can also be argued that it's safest. But it can also be argued that it should be consistent with `hg revert -a`. Note that in this mode, you can edit the hunks and it will do what you expect (e.g. add new lines to your file if you added a new lines when editing). The test case shows that that works. Differential Revision: https://phab.mercurial-scm.org/D6125
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 12 Mar 2019 14:17:41 -0700
parents d783c937aa53
children db72f9f6580e
comparison
equal deleted inserted replaced
41986:95e4ae86329f 41987:c1d83d916e85
442 $ hg revert -i<<EOF 442 $ hg revert -i<<EOF
443 > n 443 > n
444 > EOF 444 > EOF
445 add back removed file a (Yn)? n 445 add back removed file a (Yn)? n
446 $ ls 446 $ ls
447 $ hg revert -a
448 undeleting a
447 $ cd .. 449 $ cd ..
450
451 Test "keep" mode
452
453 $ cat <<EOF >> $HGRCPATH
454 > [experimental]
455 > revert.interactive.select-to-keep = true
456 > EOF
457
458 $ cd repo
459 $ printf "x\na\ny\n" > a
460 $ hg diff
461 diff -r cb9a9f314b8b a
462 --- a/a Thu Jan 01 00:00:00 1970 +0000
463 +++ b/a Thu Jan 01 00:00:00 1970 +0000
464 @@ -1,1 +1,3 @@
465 +x
466 a
467 +y
468 $ cat > $TESTTMP/editor.sh << '__EOF__'
469 > echo "+new line" >> "$1"
470 > __EOF__
471
472 $ HGEDITOR="\"sh\" \"${TESTTMP}/editor.sh\"" hg revert -i <<EOF
473 > y
474 > n
475 > e
476 > EOF
477 diff --git a/a b/a
478 2 hunks, 2 lines changed
479 examine changes to 'a'? [Ynesfdaq?] y
480
481 @@ -1,1 +1,2 @@
482 +x
483 a
484 keep change 1/2 to 'a'? [Ynesfdaq?] n
485
486 @@ -1,1 +2,2 @@
487 a
488 +y
489 keep change 2/2 to 'a'? [Ynesfdaq?] e
490
491 reverting a
492 $ cat a
493 a
494 y
495 new line