From: Dmitry Gutov Date: Sat, 28 Jan 2023 01:17:39 +0000 (+0200) Subject: Make project-current not error out inside non-existent dirs X-Git-Tag: emacs-29.0.90~580 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=128a999bfe7ebafd78e2b463586156fc6972181d;p=emacs.git Make project-current not error out inside non-existent dirs * lisp/progmodes/project.el (project-try-vc): Use condition-case to catch 'file-missing' (bug#61107). * test/lisp/progmodes/project-tests.el (project-vc-nonexistent-directory-no-error): New test. --- diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 59270070484..2343adf4698 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1,7 +1,7 @@ ;;; project.el --- Operations on the current project -*- lexical-binding: t; -*- ;; Copyright (C) 2015-2023 Free Software Foundation, Inc. -;; Version: 0.9.5 +;; Version: 0.9.6 ;; Package-Requires: ((emacs "26.1") (xref "1.4.0")) ;; This is a GNU ELPA :core package. Avoid using functionality that @@ -530,7 +530,10 @@ project backend implementation of `project-external-roots'.") dir (lambda (d) ;; Maybe limit count to 100 when we can drop Emacs < 28. - (setq last-matches (directory-files d nil marker-re t))))) + (setq last-matches + (condition-case nil + (directory-files d nil marker-re t) + (file-missing nil)))))) (backend (cl-find-if (lambda (b) diff --git a/test/lisp/progmodes/project-tests.el b/test/lisp/progmodes/project-tests.el index aea0666629d..5a206b67db1 100644 --- a/test/lisp/progmodes/project-tests.el +++ b/test/lisp/progmodes/project-tests.el @@ -152,4 +152,14 @@ When `project-ignores' includes a name matching project dir." (should (equal '(".dir-locals.el" "foo") (mapcar #'file-name-nondirectory (project-files project)))))) +(ert-deftest project-vc-nonexistent-directory-no-error () + "Check that is doesn't error out when the current dir does not exist." + (skip-unless (eq (vc-responsible-backend default-directory) 'Git)) + (let* ((dir (expand-file-name "foo-456/bar/" (ert-resource-directory))) + (_ (vc-file-clearprops dir)) + (project-vc-extra-root-markers '(".dir-locals.el")) + (project (project-current nil dir))) + (should-not (null project)) + (should (string-match-p "/test/lisp/progmodes/project-resources/\\'" (project-root project))))) + ;;; project-tests.el ends here