From b5354531bac4ea261d66804ac81be222fdeaaec2 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 13 Aug 2014 04:42:33 -0400 Subject: [PATCH] Add smerge support to the git back end. --- lisp/ChangeLog | 11 ++++++++--- lisp/vc/vc-git.el | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 764d6d12c8a..39ab7caf874 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,8 +1,13 @@ 2014-08-13 Eric S. Raymond - * vc/vc-git.el (vc-git-conflicted-files): Integrate Rüdiger - Sonderfeld's code for detecting conflicted files using a status - listing. Useful in itself and a step towards better smerge + * vc/vc.git.el: (vc-git-find-file-hook): New function. Adds + support for calling smerge on a conflicted file, and calling git + add when there are no longer conflict markers in a saved file. + This is a completed version of Rüdiger Sonderfeld's proposal. + + * vc/vc-git.el (vc-git-conflicted-files): New function. Integrate + Rüdiger Sonderfeld's code for detecting conflicted files using a + status listing. Useful in itself and a step towards better smerge support. 2014-08-12 Stefan Monnier diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 3e9228601d8..27a2f8b3d4d 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -101,7 +101,7 @@ ;; - clear-headers () NOT NEEDED ;; - delete-file (file) OK ;; - rename-file (old new) OK -;; - find-file-hook () NOT NEEDED +;; - find-file-hook () OK ;; - conflicted-files OK ;;; Code: @@ -786,6 +786,26 @@ This prompts for a branch to merge from." "DU" "AA" "UU")) (push file files))))))) +(defun vc-git-resolve-when-done () + "Call \"git add\" if the conflict markers have been removed." + (save-excursion + (goto-char (point-min)) + (unless (re-search-forward "^<<<<<<< " nil t) + (vc-git-command nil 0 buffer-file-name "add") + ;; Remove the hook so that it is not called multiple times. + (remove-hook 'after-save-hook 'vc-git-resolve-when-done t)))) + +(defun vc-git-find-file-hook () + "Activate `smerge-mode' if there is a conflict." + (when (and buffer-file-name + (vc-git-conflicted-files buffer-file-name) + (save-excursion + (goto-char (point-min)) + (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) + (message "There are unresolved conflicts in this file"))) ;;; HISTORY FUNCTIONS -- 2.39.5