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>
;; - 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:
"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