]> git.eshelyaron.com Git - emacs.git/commitdiff
Make project-current not error out inside non-existent dirs
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 28 Jan 2023 01:17:39 +0000 (03:17 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 28 Jan 2023 01:20:29 +0000 (03:20 +0200)
* 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.

lisp/progmodes/project.el
test/lisp/progmodes/project-tests.el

index 59270070484baae47f92018bb03af084f75c2c6c..2343adf4698471cf5262ce7a4340a4b0c5b5fa7e 100644 (file)
@@ -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)
index aea0666629d9d0d200037f16e521eb055eabca48..5a206b67db1952d893d632c1ac4757ddfd00507f 100644 (file)
@@ -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