1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Fix '(vc-revert-file (vc-git-root)'

* lisp/vc/vc-git.el (vc-git--file-list-is-rootdir):
Merge into vc-git-command.
(vc-git-command): When operating on the repository root, first
bind default-directory to that root.  When operating on the
repository root with 'git checkout', pass "." as FILE-OR-LIST.
This commit is contained in:
Sean Whitton 2025-11-20 20:42:21 +00:00
parent 896449d65a
commit 0bf1eb692b

View file

@ -2711,7 +2711,7 @@ page for the meanings of these attributes."
"A wrapper around `vc-do-command' for use in vc-git.el. "A wrapper around `vc-do-command' for use in vc-git.el.
The difference to `vc-do-command' is that this function always invokes The difference to `vc-do-command' is that this function always invokes
`vc-git-program'." `vc-git-program'."
(let ((coding-system-for-read (let* ((coding-system-for-read
(or coding-system-for-read vc-git-log-output-coding-system)) (or coding-system-for-read vc-git-log-output-coding-system))
;; Commands which pass command line arguments which might ;; Commands which pass command line arguments which might
;; contain non-ASCII have to bind `coding-system-for-write' to ;; contain non-ASCII have to bind `coding-system-for-write' to
@ -2729,27 +2729,39 @@ The difference to `vc-do-command' is that this function always invokes
(process-environment (process-environment
(append (append
`("GIT_DIR" `("GIT_DIR"
,@(when vc-git-use-literal-pathspecs ,@(and vc-git-use-literal-pathspecs
'("GIT_LITERAL_PATHSPECS=1")) '("GIT_LITERAL_PATHSPECS=1"))
;; Avoid repository locking during background operations ;; Avoid repository locking during background operations
;; (bug#21559). ;; (bug#21559).
,@(when revert-buffer-in-progress ,@(and revert-buffer-in-progress
'("GIT_OPTIONAL_LOCKS=0"))) '("GIT_OPTIONAL_LOCKS=0")))
process-environment))) process-environment))
(file1 (and (not (cdr-safe file-or-list))
(or (car-safe file-or-list) file-or-list)))
(file-list-is-rootdir (and file1
(directory-name-p file1)
(equal file1 (vc-git-root file1))))
(default-directory (if file-list-is-rootdir
file1
default-directory)))
(apply #'vc-do-command (or buffer "*vc*") okstatus vc-git-program (apply #'vc-do-command (or buffer "*vc*") okstatus vc-git-program
;; https://debbugs.gnu.org/16897 ;; Three cases:
(unless (vc-git--file-list-is-rootdir file-or-list) ;; - operating on root directory and command is one where doing
file-or-list) ;; so requires passing "." to have the usual effect
;; (e.g. 'git checkout --' will do nothing;
;; 'git checkout -- .' will revert all files as desired)
;; - operating on root directory and command is one where we
;; must pass no list of files to have the usual effect
;; (e.g. 'git log' for root logs as discussed in bug#16897)
;; - not operating on root directory,
;; pass FILE-OR-LIST along as normal.
(cond ((and file-list-is-rootdir
(member (car flags) '("checkout")))
".")
((not file-list-is-rootdir)
file-or-list))
(cons "--no-pager" flags)))) (cons "--no-pager" flags))))
(defun vc-git--file-list-is-rootdir (file-or-list)
(and (not (cdr-safe file-or-list))
(let ((file (or (car-safe file-or-list)
file-or-list)))
(and file
(directory-name-p file)
(equal file (vc-git-root file))))))
(defun vc-git--empty-db-p () (defun vc-git--empty-db-p ()
"Check if the git db is empty (no commit done yet)." "Check if the git db is empty (no commit done yet)."
(let (process-file-side-effects) (let (process-file-side-effects)