Attempt to recognise if a VC package has no Elisp files

* lisp/emacs-lisp/package-vc.el (package-vc-non-code-file-names): Add
new variable used to avoid false-positives.
(package-vc--unpack): Recursively search for .el files excluding the
ones listed in 'package-vc-non-code-file-names', offering to abort the
installation if none are found.
This commit is contained in:
Philip Kaludercic 2023-02-16 11:11:23 +01:00
parent 2550e8bb0b
commit 1c9d81a2b4

View file

@ -602,6 +602,13 @@ attribute in PKG-SPEC."
(vc-retrieve-tag dir release-rev)
(message "No release revision was found, continuing...")))))
(defvar package-vc-non-code-file-names
'(".dir-locals.el" ".dir-locals-2.el")
"List of file names that do not contain Emacs Lisp code.
This list is used by `package-vc--unpack' to better check if the
user is fetching code from a repository that does not contain any
Emacs Lisp files.")
(defun package-vc--unpack (pkg-desc pkg-spec &optional rev)
"Install the package described by PKG-DESC.
PKG-SPEC is a package specification, a property list describing
@ -623,6 +630,14 @@ checkout. This overrides the `:branch' attribute in PKG-SPEC."
(when (directory-empty-p pkg-dir)
(delete-directory pkg-dir)
(error "Empty checkout for %s" name))
(unless (seq-remove
(lambda (file)
(member (file-name-nondirectory file) package-vc-non-code-file-names))
(directory-files-recursively pkg-dir "\\.el\\'" nil))
(when (yes-or-no-p (format "No Emacs Lisp files found when fetching \"%s\", \
abort installation?" name))
(delete-directory pkg-dir t)
(user-error "Installation aborted")))
;; When nothing is specified about a `lisp-dir', then should
;; heuristically check if there is a sub-directory with lisp