From 22fc36dba7078f1b6938b2c06abc82e073ff3688 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 31 Aug 2024 00:45:43 -0400 Subject: [PATCH] fix(lib): doom/add-directory-as-project If the target directory wasn't in a project, this command would throw a type error (see #8032). This also adds more checks and informative error handling to the command. Fix: #8032 --- lisp/lib/projects.el | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lisp/lib/projects.el b/lisp/lib/projects.el index 3a38750d9..b320f8a14 100644 --- a/lisp/lib/projects.el +++ b/lisp/lib/projects.el @@ -79,16 +79,21 @@ file will be created within it so that it will always be treated as one. This command will throw an error if a parent of DIR is a valid project (which would mask DIR)." (interactive "D") + (when-let ((proj-dir (doom-project-root dir))) + (if (file-equal-p proj-dir dir) + (user-error "ERROR: Directory is already a project: %s" proj-dir) + (user-error "ERROR: Directory is already inside another project: %s" proj-dir))) (let ((short-dir (abbreviate-file-name dir))) - (unless (file-equal-p (doom-project-root dir) dir) - (with-temp-file (doom-path dir ".project"))) - (let ((proj-dir (doom-project-root dir))) - (unless (file-equal-p proj-dir dir) - (user-error "Can't add %S as a project, because %S is already a project" - short-dir (abbreviate-file-name proj-dir))) - (message "%S was not a project; adding .project file to it" - short-dir (abbreviate-file-name proj-dir)) - (projectile-add-known-project dir)))) + (when (projectile-ignored-project-p dir) + (user-error "ERROR: Directory is in projectile's ignore list: %s" short-dir)) + (dolist (proj projectile-known-projects) + (when (file-in-directory-p proj dir) + (user-error "ERROR: Directory contains a known project: %s" short-dir)) + (when (file-equal-p proj dir) + (user-error "ERROR: Directory is already a known project: %s" short-dir))) + (with-temp-file (doom-path dir ".project")) + (message "Added directory as a project: %s" short-dir) + (projectile-add-known-project dir))) ;;