aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2015-04-22 04:45:43 +0300
committerDmitry Gutov2015-04-22 04:59:48 +0300
commitdbd65c779aa648bcc5c6fdc31f0be44cce4ea8ce (patch)
tree185fcc46c6d325cc994535bd935b0f873f4223cc
parent3f2c8b82649b670bdccfdc2235b3fb0b63a90d4c (diff)
downloademacs-dbd65c779aa648bcc5c6fdc31f0be44cce4ea8ce.tar.gz
emacs-dbd65c779aa648bcc5c6fdc31f0be44cce4ea8ce.zip
Add or reset based on the presence of MERGE_HEAD
* lisp/vc/vc-git.el (vc-git-find-file-hook): Add `vc-git-resolve-when-done' to `after-save-hook' in either case. (vc-git-conflicted-files): Add a TODO. (vc-git-resolve-when-done): Depending on the presence of MERGE_HEAD, either update the resolved file in the index, or remove it from there. (Bug#20292)
-rw-r--r--lisp/vc/vc-git.el43
1 files changed, 22 insertions, 21 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index bec36fd3e98..c8b696a03bb 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -771,6 +771,9 @@ This prompts for a branch to merge from."
771 (vc-git--run-command-string directory "status" "--porcelain" "--")) 771 (vc-git--run-command-string directory "status" "--porcelain" "--"))
772 (lines (when status (split-string status "\n" 'omit-nulls))) 772 (lines (when status (split-string status "\n" 'omit-nulls)))
773 files) 773 files)
774 ;; TODO: Look into reimplementing `vc-git-state', as well as
775 ;; `vc-git-dir-status-files', based on this output, thus making the
776 ;; extra process call in `vc-git-find-file-hook' unnecessary.
774 (dolist (line lines files) 777 (dolist (line lines files)
775 (when (string-match "\\([ MADRCU?!][ MADRCU?!]\\) \\(.+\\)\\(?: -> \\(.+\\)\\)?" 778 (when (string-match "\\([ MADRCU?!][ MADRCU?!]\\) \\(.+\\)\\(?: -> \\(.+\\)\\)?"
776 line) 779 line)
@@ -786,32 +789,30 @@ This prompts for a branch to merge from."
786 (save-excursion 789 (save-excursion
787 (goto-char (point-min)) 790 (goto-char (point-min))
788 (unless (re-search-forward "^<<<<<<< " nil t) 791 (unless (re-search-forward "^<<<<<<< " nil t)
789 (vc-git-command nil 0 buffer-file-name "add") 792 (if (file-exists-p (expand-file-name ".git/MERGE_HEAD"
793 (vc-git-root buffer-file-name)))
794 ;; Doing a merge.
795 (vc-git-command nil 0 buffer-file-name "add")
796 ;; Doing something else. Likely applying a stash (bug#20292).
797 (vc-git-command nil 0 buffer-file-name "reset"))
790 ;; Remove the hook so that it is not called multiple times. 798 ;; Remove the hook so that it is not called multiple times.
791 (remove-hook 'after-save-hook 'vc-git-resolve-when-done t)))) 799 (remove-hook 'after-save-hook 'vc-git-resolve-when-done t))))
792 800
793(defun vc-git-find-file-hook () 801(defun vc-git-find-file-hook ()
794 "Activate `smerge-mode' if there is a conflict." 802 "Activate `smerge-mode' if there is a conflict."
795 (let (stashed) 803 (when (and buffer-file-name
796 (when (and buffer-file-name 804 ;; FIXME
797 ;; FIXME 805 ;; 1) the net result is to call git twice per file.
798 ;; 1) the net result is to call git twice per file. 806 ;; 2) v-g-c-f is documented to take a directory.
799 ;; 2) v-g-c-f is documented to take a directory. 807 ;; http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01126.html
800 ;; http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01126.html 808 (vc-git-conflicted-files buffer-file-name)
801 ;; XXX: Should we first look for the markers, and only 809 (save-excursion
802 ;; call this function when see some? 810 (goto-char (point-min))
803 (vc-git-conflicted-files buffer-file-name) 811 (re-search-forward "^<<<<<<< " nil 'noerror)))
804 (save-excursion 812 (vc-file-setprop buffer-file-name 'vc-state 'conflict)
805 (goto-char (point-min)) 813 (smerge-start-session)
806 (when (re-search-forward "^>>>>>>> " nil 'noerror) 814 (add-hook 'after-save-hook 'vc-git-resolve-when-done nil 'local)
807 (setq stashed (looking-at "Stashed changes")) 815 (message "There are unresolved conflicts in this file")))
808 t)))
809 (vc-file-setprop buffer-file-name 'vc-state 'conflict)
810 (smerge-start-session)
811 (unless stashed
812 ;; Stashes are tricky (bug#20292).
813 (add-hook 'after-save-hook 'vc-git-resolve-when-done nil 'local))
814 (message "There are unresolved conflicts in this file"))))
815 816
816;;; HISTORY FUNCTIONS 817;;; HISTORY FUNCTIONS
817 818