I highly encourage the magit maintainers to apply this patch or
something like it (possible changes include making confirmation on by
default or not even an option, and adding a space after the ? in the
prompt).  I just lost a whole bunch of uncommitted changes by
accidentally hitting v instead of c when my point was on the file
header line of a file expanded as a diff and this was very frustrating
and unexpected.

--dave

On Mar 31, 10:10 am, Ramkumar Ramachandra <[email protected]> wrote:
> Add an option to confirm reverting an item.
>
> Signed-off-by: Ramkumar Ramachandra <[email protected]>
> ---
>  magit.el |   28 ++++++++++++++++++----------
>  1 files changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/magit.el b/magit.el
> index d81b454..84ceaa4 100644
> --- a/magit.el
> +++ b/magit.el
> @@ -123,6 +123,11 @@ Setting this to nil will make it do nothing,
> setting it to t will arrange things
>                  (const :tag "Immediately" 0)
>                  (integer :tag "After this many seconds")))
>
> +(defcustom magit-revert-item-confirm nil
> +  "Require acknowledgment before reverting an item"
> +  :group 'magit
> +  :type 'boolean)
> +
>  (defcustom magit-log-edit-confirm-cancellation nil
>    "Require acknowledgment before canceling the log edit buffer."
>    :group 'magit
> @@ -3182,16 +3187,19 @@ Prefix arg means justify as well."
>
>  (defun magit-revert-item ()
>    (interactive)
> -  (magit-section-action (item info "revert")
> -    ((pending commit)
> -     (magit-apply-commit info nil nil t)
> -     (magit-rewrite-set-commit-property info 'used nil))
> -    ((commit)
> -     (magit-apply-commit info nil nil t))
> -    ((hunk)
> -     (magit-apply-hunk-item-reverse item))
> -    ((diff)
> -     (magit-apply-diff-item item "--reverse"))))
> +  (when (or (not magit-revert-item-confirm)
> +           (yes-or-no-p
> +            "Really revert this item (cannot be undone)?"))
> +    (magit-section-action (item info "revert")
> +      ((pending commit)
> +       (magit-apply-commit info nil nil t)
> +       (magit-rewrite-set-commit-property info 'used nil))
> +      ((commit)
> +       (magit-apply-commit info nil nil t))
> +      ((hunk)
> +       (magit-apply-hunk-item-reverse item))
> +      ((diff)
> +       (magit-apply-diff-item item "--reverse")))))
>
>  (defvar magit-have-graph 'unset)
>  (defvar magit-have-decorate 'unset)
> --
> 1.7.0.3

Reply via email to