Make marking conflicted files as resolved upon saving opt-out

This fixes Bug#3860.

* lisp/vc/vc.el (vc-resolve-conflicts): New user option.
* lisp/vc/vc-bzr.el (vc-bzr-resolve-conflicts): New user option.
(vc-bzr-find-file-hook): Use it.
* lisp/vc/vc-hg.el (vc-hg-resolve-conflicts): New user option.
(vc-hg-find-file-hook): Use it.
* lisp/vc/vc-svn.el (vc-svn-resolve-conflicts): New user option.
(vc-svn-find-file-hook): Use it.
* lisp/vc/vc-git.el (vc-git-resolve-conflicts): Support
'default' as an option.  Adjust docstring and version.
(vc-git-find-file-hook): Respect vc-resolve-conflicts.
* etc/NEWS: Announce the new options.
This commit is contained in:
Mauro Aranda 2025-03-17 06:55:07 -03:00
parent 86be9431ae
commit acb96a5ca8
6 changed files with 84 additions and 9 deletions

View file

@ -1405,6 +1405,18 @@ It is intended to be added to the 'log-edit-done-hook' so that
'vc-cvs-checkin' behaves like invoking 'cvs commit [files...]' from the
command line.
---
*** New user options 'vc-resolve-conflicts', 'vc-*-resolve-conflicts'
Control whether to mark a conflicted file as resolved when saving.
You can now control it globally, with 'vc-resolve-conflicts' or for
specific backends with 'vc-bzr-resolve-conflicts',
'vc-hg-resolve-conflicts' and 'vc-svn-resolve-conflicts'.
---
*** New value for 'vc-git-resolve-conflicts'
The option now accepts the symbol 'default' as a value, which is
its default value. Effectively, the default value hasn't changed,
since 'vc-resolve-conflicts' defaults to t, the previous default value
for 'vc-git-resolve-conflicts'.
** Diff mode
+++

View file

@ -110,6 +110,16 @@ The option \"--no-classify\" should be present if your bzr supports it."
(repeat :tag "Argument List" :value ("") string))
:version "24.1")
(defcustom vc-bzr-resolve-conflicts 'default
"Whether to mark conflicted file as resolved upon saving.
If this is t and there are no more conflict markers in the file,
VC will mark the conflicts in the saved file as resolved.
A value of `default' means to use the value of `vc-resolve-conflicts'."
:type '(choice (const :tag "Don't resolve" nil)
(const :tag "Resolve" t)
(const :tag "Use vc-resolve-conflicts" default))
:version "31.1")
;; since v0.9, bzr supports removing the progress indicators
;; by setting environment variable BZR_PROGRESS_BAR to "none".
(defun vc-bzr-command (bzr-command buffer okstatus file-or-list &rest args)
@ -531,7 +541,10 @@ in the branch repository (or whose status not be determined)."
;; but the one in `bzr pull' isn't, so it would be good to provide an
;; elisp function to remerge from the .BASE/OTHER/THIS files.
(smerge-start-session)
(add-hook 'after-save-hook #'vc-bzr-resolve-when-done nil t)
(when (or (eq vc-bzr-resolve-conflicts t)
(and (eq vc-bzr-resolve-conflicts 'default)
vc-resolve-conflicts))
(add-hook 'after-save-hook #'vc-bzr-resolve-when-done nil t))
(vc-message-unresolved-conflicts buffer-file-name)))
(defun vc-bzr-clone (remote directory rev)

View file

@ -166,17 +166,24 @@ uses a full scan)."
(repeat :tag "Argument List" :value ("") string))
:version "30.1")
(defcustom vc-git-resolve-conflicts t
"When non-nil, mark conflicted file as resolved upon saving.
(defcustom vc-git-resolve-conflicts 'default
"Whether to mark conflicted file as resolved upon saving.
That is performed after all conflict markers in it have been removed.
If this is t and there are no more conflict markers in the file,
VC will mark the conflicts in the saved file as resolved.
If the value is `unstage-maybe', and no merge, rebase or similar
operation is in progress, then after the last conflict is resolved, also
clear the staging area."
clear the staging area.
A value of `default' means to use the value of `vc-resolve-conflicts'."
:type '(choice (const :tag "Don't resolve" nil)
(const :tag "Resolve" t)
(const :tag "Resolve and maybe unstage all files"
unstage-maybe))
:version "25.1")
unstage-maybe)
(const :tag "Use vc-resolve-conflicts" default))
:version "31.1")
(defcustom vc-git-program "git"
"Name of the Git executable (excluding any arguments)."
@ -1445,7 +1452,9 @@ This prompts for a branch to merge from."
(goto-char (point-min))
(re-search-forward "^<<<<<<< " nil 'noerror)))
(smerge-start-session)
(when vc-git-resolve-conflicts
(unless (or (null vc-git-resolve-conflicts)
(and (eq vc-git-resolve-conflicts 'default)
(not vc-resolve-conflicts)))
(add-hook 'after-save-hook #'vc-git-resolve-when-done nil 'local))
(vc-message-unresolved-conflicts buffer-file-name)))

View file

@ -183,6 +183,16 @@ If `ask', you will be prompted for a branch type."
(const :tag "Ask" ask))
:version "28.1")
(defcustom vc-hg-resolve-conflicts 'default
"Whether to mark conflicted file as resolved upon saving.
If this is t and there are no more conflict markers in the file,
VC will mark the conflicts in the saved file as resolved.
A value of `default' means to use the value of `vc-resolve-conflicts'."
:type '(choice (const :tag "Don't resolve" nil)
(const :tag "Resolve" t)
(const :tag "Use vc-resolve-conflicts" default))
:version "31.1")
;; Clear up the cache to force vc-call to check again and discover
;; new functions when we reload this file.
@ -1263,7 +1273,10 @@ REV is the revision to check out into WORKFILE."
;; Hg may not recognize "conflict" as a state, but we can do better.
(vc-file-setprop buffer-file-name 'vc-state 'conflict)
(smerge-start-session)
(add-hook 'after-save-hook #'vc-hg-resolve-when-done nil t)
(when (or (eq vc-hg-resolve-conflicts t)
(and (eq vc-hg-resolve-conflicts 'default)
vc-resolve-conflicts))
(add-hook 'after-save-hook #'vc-hg-resolve-when-done nil t))
(vc-message-unresolved-conflicts buffer-file-name)))
(defun vc-hg-clone (remote directory rev)

View file

@ -106,6 +106,16 @@ switches."
:version "24.1" ; no longer consult the obsolete vc-header-alist
:type '(repeat string))
(defcustom vc-svn-resolve-conflicts 'default
"Whether to mark conflicted file as resolved upon saving.
If this is t and there are no more conflict markers in the file,
VC will mark the conflicts in the saved file as resolved.
A value of `default' means to use the value of `vc-resolve-conflicts'."
:type '(choice (const :tag "Don't resolve" nil)
(const :tag "Resolve" t)
(const :tag "Use vc-resolve-conflicts" default))
:version "31.1")
;; We want to autoload it for use by the autoloaded version of
;; vc-svn-registered, but we want the value to be compiled at startup, not
;; at dump time.
@ -688,7 +698,10 @@ and that it passes `vc-svn-global-switches' to it before FLAGS."
;; There are conflict markers.
(progn
(smerge-start-session)
(add-hook 'after-save-hook #'vc-svn-resolve-when-done nil t))
(when (or (eq vc-svn-resolve-conflicts t)
(and (eq vc-svn-resolve-conflicts 'default)
vc-resolve-conflicts))
(add-hook 'after-save-hook #'vc-svn-resolve-when-done nil t)))
;; There are no conflict markers. This is problematic: maybe it means
;; the conflict has been resolved and we should immediately call "svn
;; resolved", or it means that the file's type does not allow Svn to

View file

@ -999,6 +999,21 @@ the URL-REGEXP of the association."
:value-type ,vc-cloneable-backends-custom-type)
:version "31.1")
(defcustom vc-resolve-conflicts t
"Whether to mark conflicted file as resolved upon saving.
If this is non-nil and there are no more conflict markers in the file,
VC will mark the conflicts in the saved file as resolved. This is
only meaningful for VCS that handle conflicts by inserting conflict
markers in a conflicted file.
When saving a conflicted file, VC first tries to use the value
of `vc-BACKEND-resolve-conflicts', for handling backend-specific
settings. It defaults to this option if that option has the special
value `default'."
:type 'boolean
:version "31.1")
;; File property caching