1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Fix some 'git worktree' compatibility issues

* lisp/vc/vc-git.el (vc-git-delete-working-tree): Reimplement to
avoid requiring 'git worktree remove'.
(vc-git-move-working-tree): Use 'git worktree move' if 'git
worktree repair' is not available.  Give a more informative
error message if we don't even have that.
* test/lisp/vc/vc-tests/vc-tests.el (vc-git--program-version):
Declare.
(vc-test--other-working-trees): Skip vc-move-working-tree tests
with Git old enough to lack 'git worktree move'.
This commit is contained in:
Sean Whitton 2025-08-10 13:25:41 +01:00
parent 11d521e6e4
commit 66eead6fd0
3 changed files with 50 additions and 34 deletions

View file

@ -2459,16 +2459,27 @@ page for the meanings of these attributes."
(defun vc-git-delete-working-tree (directory)
"Implementation of `delete-working-tree' backend function for Git."
(vc-git-command nil 0 nil "worktree" "remove" "-f"
(expand-file-name directory)))
;; Avoid assuming we have 'git worktree remove' which older Git lacks.
(delete-directory directory t t)
(vc-git-command nil 0 nil "worktree" "prune"))
(defun vc-git-move-working-tree (from to)
"Implementation of `move-working-tree' backend function for Git."
;; 'git worktree move' can't move the main worktree, but moving and
;; then repairing like this can.
(rename-file from (directory-file-name to) 1)
(let ((default-directory to))
(vc-git-command nil 0 nil "worktree" "repair")))
(let ((v (vc-git--program-version)))
(cond ((version<= "2.29" v)
;; 'git worktree move' can't move the main worktree,
;; but moving and then repairing can.
(rename-file from (directory-file-name to) 1)
(let ((default-directory to))
(vc-git-command nil 0 nil "worktree" "repair")))
((version<= "2.17" v)
;; We lack 'git worktree repair' but have 'git worktree move'.
(vc-git-command nil 0 nil "worktree" "move"
(expand-file-name from)
(expand-file-name to)))
(t
;; We don't even have 'git worktree move'.
(error "Your Git is too old to relocate other working trees")))))
;;; Internal commands