]> code.delx.au - gnu-emacs/commitdiff
Add smerge support to the git back end.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 13 Aug 2014 08:42:33 +0000 (04:42 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 13 Aug 2014 08:42:33 +0000 (04:42 -0400)
lisp/ChangeLog
lisp/vc/vc-git.el

index 764d6d12c8aa3d1e3fd9f0c15e96ec42708e1266..39ab7caf87490587b4624864686567cd87c92872 100644 (file)
@@ -1,8 +1,13 @@
 2014-08-13  Eric S. Raymond  <esr@thyrsus.com>
 
-       * 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  <monnier@iro.umontreal.ca>
index 3e9228601d840b15d85e58e3a8d154dc90e77037..27a2f8b3d4d584dcf3cc03b82d38103d30da3e1a 100644 (file)
 ;; - 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