unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: esr@snark.thyrsus.com, 20292@debbugs.gnu.org
Subject: bug#20292: 24.5; Saving Git-controlled file with merge conflicts after "stash pop" stages the file
Date: Sat, 16 May 2015 02:50:57 +0300	[thread overview]
Message-ID: <55568661.90506@yandex.ru> (raw)
In-Reply-To: <jwvoalmzy2y.fsf-monnier+emacsbugs@gnu.org>

On 05/14/2015 11:55 PM, Stefan Monnier wrote:
>
> I think the only sane way to handle this is to always use "git add" and
> to add a config var so users who don't like it can disable it.

If we're fine with a config var, we might as well try to support the 
alternative behavior. This should do it:

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 20f2101..2fbb71b 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -130,6 +130,17 @@ If nil, use the value of `vc-annotate-switches'. 
If t, use no switches."
    :version "25.1"
    :group 'vc-git)

+(defcustom vc-git-resolve-conflicts t
+  "When non-nil, mark conflicted file as resolved upon saving.
+That happens after all conflict markers in it have been removed.
+If the value is `unstage', then after the last conflict is
+resolved, the staging area is cleared if no merge is in progress."
+  :type '(choice (const :tag "Don't resolve" nil)
+                 (const :tag "Resolve" t)
+                 (const :tag "Unstage all after resolving" unstage))
+  :version "25.1"
+  :group 'vc-git)
+
  (defcustom vc-git-program "git"
    "Name of the Git executable (excluding any arguments)."
    :version "24.1"
@@ -801,12 +812,16 @@ This prompts for a branch to merge from."
    (save-excursion
      (goto-char (point-min))
      (unless (re-search-forward "^<<<<<<< " nil t)
-      (if (file-exists-p (expand-file-name ".git/MERGE_HEAD"
-                                           (vc-git-root buffer-file-name)))
-          ;; Doing a merge.
-          (vc-git-command nil 0 buffer-file-name "add")
-        ;; Doing something else.  Likely applying a stash (bug#20292).
-        (vc-git-command nil 0 buffer-file-name "reset"))
+      (vc-git-command nil 0 buffer-file-name "add")
+      (when (and
+             (eq vc-git-resolve-conflicts 'unstage)
+             ;; Doing something other than a merge.  Likely applying a
+             ;; stash (bug#20292).
+             (not
+              (file-exists-p (expand-file-name ".git/MERGE_HEAD"
+                                               (vc-git-root 
buffer-file-name))))
+             (not (vc-git-conflicted-files (vc-git-root 
buffer-file-name))))
+        (vc-git-command nil 0 nil "reset"))
        ;; Remove the hook so that it is not called multiple times.
        (remove-hook 'after-save-hook 'vc-git-resolve-when-done t))))

@@ -823,7 +838,8 @@ This prompts for a branch to merge from."
                 (re-search-forward "^<<<<<<< " nil 'noerror)))
      (vc-file-setprop buffer-file-name 'vc-state 'conflict)
      (smerge-start-session)
-    (add-hook 'after-save-hook 'vc-git-resolve-when-done nil 'local)
+    (when vc-git-resolve-conflicts
+      (add-hook 'after-save-hook 'vc-git-resolve-when-done nil 'local))
      (message "There are unresolved conflicts in this file")))

  ;;; HISTORY FUNCTIONS






  parent reply	other threads:[~2015-05-15 23:50 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10 12:55 bug#20292: 24.5; Saving Git-controlled file with merge conflicts after "stash pop" stages the file Eli Zaretskii
2015-04-18 19:16 ` Dmitry Gutov
2015-04-18 19:31   ` Eli Zaretskii
2015-04-18 21:58     ` Dmitry Gutov
2015-04-18 22:06       ` Dmitry Gutov
2015-04-19 14:30       ` Eli Zaretskii
2015-04-19 16:28         ` Dmitry Gutov
2015-04-19 17:06           ` Eli Zaretskii
2015-04-19 17:38             ` Dmitry Gutov
2015-04-19 18:05               ` Eli Zaretskii
2015-04-19 18:11                 ` Dmitry Gutov
2015-04-19 18:25                   ` Eli Zaretskii
2015-04-19 18:30                     ` Dmitry Gutov
2015-04-19 18:38                       ` Eli Zaretskii
2015-04-19 19:27                         ` Dmitry Gutov
2015-04-19 19:33                           ` Eli Zaretskii
2015-04-20  2:41                       ` Stefan Monnier
2015-04-20 14:45                         ` Eli Zaretskii
2015-04-20 19:20                           ` Stefan Monnier
2015-04-20 19:23                             ` Eli Zaretskii
2015-04-21  1:06                               ` Stefan Monnier
2015-04-22  1:50                                 ` Dmitry Gutov
2015-04-22  7:35                                   ` Eli Zaretskii
2015-05-12 23:13                                     ` Dmitry Gutov
2015-05-13 13:04                                       ` Stefan Monnier
2015-05-13 16:20                                         ` Eli Zaretskii
2015-05-13 16:18                                       ` Eli Zaretskii
2015-05-14  1:24                                         ` Dmitry Gutov
2015-05-14 14:53                                           ` Eli Zaretskii
2015-05-14 18:00                                             ` Dmitry Gutov
2015-05-14 18:49                                               ` Eli Zaretskii
2015-05-14  3:49                                         ` Stefan Monnier
2015-05-14 14:53                                           ` Eli Zaretskii
2015-05-14 15:51                                             ` Stefan Monnier
2015-05-14 17:30                                               ` Dmitry Gutov
2015-05-14 18:36                                                 ` Eli Zaretskii
2015-05-14 18:48                                                   ` Dmitry Gutov
2015-05-14 18:52                                                     ` Eli Zaretskii
2015-05-14 19:09                                                       ` Dmitry Gutov
2015-05-14 19:33                                                         ` Eli Zaretskii
2015-05-14 20:24                                                           ` Dmitry Gutov
2015-05-14 20:55                                                             ` Stefan Monnier
2015-05-15  7:14                                                               ` Eli Zaretskii
2015-05-15 18:13                                                                 ` Stefan Monnier
2015-05-15 18:55                                                                   ` Eli Zaretskii
2015-05-15 20:02                                                                     ` Stefan Monnier
2015-05-15 20:19                                                                       ` Eli Zaretskii
2015-05-15 23:52                                                                         ` Stefan Monnier
2015-05-15 23:57                                                                           ` Dmitry Gutov
2015-05-16 13:48                                                                             ` Stefan Monnier
2015-05-15 23:50                                                               ` Dmitry Gutov [this message]
2015-05-16  7:15                                                                 ` Eli Zaretskii
2015-05-16  8:03                                                                   ` Dmitry Gutov
2015-05-16  8:55                                                                     ` Eli Zaretskii
2015-05-16 13:15                                                                       ` Dmitry Gutov
2015-05-16 13:53                                                                 ` Stefan Monnier
2015-05-16 14:13                                                                   ` Dmitry Gutov
2015-05-15  7:10                                                             ` Eli Zaretskii
2015-05-15  7:17                                                             ` Eli Zaretskii
2015-04-22  8:47                                   ` Richard Stallman
2015-04-22  9:16                                     ` Eli Zaretskii
2015-04-22 19:59                                       ` Richard Stallman
2015-04-22 21:32                                         ` Eli Zaretskii
     [not found] <xmqqd1il7lor.fsf@gitster.mtv.corp.google.com>
2016-11-16  0:25 ` Dmitry Gutov
2016-11-16 17:30   ` Eli Zaretskii
2016-11-16 22:45     ` Dmitry Gutov
2016-11-17 15:57       ` Eli Zaretskii
2016-11-17 18:04         ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55568661.90506@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=20292@debbugs.gnu.org \
    --cc=esr@snark.thyrsus.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).