aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2023-01-28 03:17:39 +0200
committerDmitry Gutov2023-01-28 03:20:29 +0200
commit128a999bfe7ebafd78e2b463586156fc6972181d (patch)
tree4658b7708be275494704bbdab35b5d16fe88ce02
parent194bc97879d2b57545eda17dbeb0b2e46b215617 (diff)
downloademacs-128a999bfe7ebafd78e2b463586156fc6972181d.tar.gz
emacs-128a999bfe7ebafd78e2b463586156fc6972181d.zip
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.
-rw-r--r--lisp/progmodes/project.el7
-rw-r--r--test/lisp/progmodes/project-tests.el10
2 files changed, 15 insertions, 2 deletions
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 @@
1;;; project.el --- Operations on the current project -*- lexical-binding: t; -*- 1;;; project.el --- Operations on the current project -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 2015-2023 Free Software Foundation, Inc. 3;; Copyright (C) 2015-2023 Free Software Foundation, Inc.
4;; Version: 0.9.5 4;; Version: 0.9.6
5;; Package-Requires: ((emacs "26.1") (xref "1.4.0")) 5;; Package-Requires: ((emacs "26.1") (xref "1.4.0"))
6 6
7;; This is a GNU ELPA :core package. Avoid using functionality that 7;; This is a GNU ELPA :core package. Avoid using functionality that
@@ -530,7 +530,10 @@ project backend implementation of `project-external-roots'.")
530 dir 530 dir
531 (lambda (d) 531 (lambda (d)
532 ;; Maybe limit count to 100 when we can drop Emacs < 28. 532 ;; Maybe limit count to 100 when we can drop Emacs < 28.
533 (setq last-matches (directory-files d nil marker-re t))))) 533 (setq last-matches
534 (condition-case nil
535 (directory-files d nil marker-re t)
536 (file-missing nil))))))
534 (backend 537 (backend
535 (cl-find-if 538 (cl-find-if
536 (lambda (b) 539 (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."
152 (should (equal '(".dir-locals.el" "foo") 152 (should (equal '(".dir-locals.el" "foo")
153 (mapcar #'file-name-nondirectory (project-files project)))))) 153 (mapcar #'file-name-nondirectory (project-files project))))))
154 154
155(ert-deftest project-vc-nonexistent-directory-no-error ()
156 "Check that is doesn't error out when the current dir does not exist."
157 (skip-unless (eq (vc-responsible-backend default-directory) 'Git))
158 (let* ((dir (expand-file-name "foo-456/bar/" (ert-resource-directory)))
159 (_ (vc-file-clearprops dir))
160 (project-vc-extra-root-markers '(".dir-locals.el"))
161 (project (project-current nil dir)))
162 (should-not (null project))
163 (should (string-match-p "/test/lisp/progmodes/project-resources/\\'" (project-root project)))))
164
155;;; project-tests.el ends here 165;;; project-tests.el ends here