Skip to content

Commit

Permalink
[Fix bbatsov#1205] Add check that project directory exists when switc…
Browse files Browse the repository at this point in the history
…hing
  • Loading branch information
kevinjfoley committed Sep 23, 2018
1 parent f91b36b commit 7000fc8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [#1285](https://github.com/bbatsov/projectile/pull/1285): Add support for Pipenv-managed Python projects.
* [#1232](https://github.com/bbatsov/projectile/issues/1232): Stop evaluating code dynamically in the mode-line and switch to a simpler scheme where the mode-line is updated just once using `find-file-hook`.
* Make the mode line configurable via `projectile-dynamic-mode-line` and `projectile-mode-line-fn`.
* [#1205](https://github.com/bbatsov/projectile/issues/1205): Check that project directory exists when switching projects.

## 1.0.0 (2018-07-21)

Expand Down
41 changes: 22 additions & 19 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -3551,25 +3551,28 @@ With a prefix ARG invokes `projectile-commander' instead of
Invokes the command referenced by `projectile-switch-project-action' on switch.
With a prefix ARG invokes `projectile-commander' instead of
`projectile-switch-project-action.'"
(let ((switch-project-action (if arg
'projectile-commander
projectile-switch-project-action)))
(run-hooks 'projectile-before-switch-project-hook)
(let ((default-directory project-to-switch))
;; use a temporary buffer to load PROJECT-TO-SWITCH's dir-locals before calling SWITCH-PROJECT-ACTION
(with-temp-buffer
(hack-dir-local-variables-non-file-buffer))
;; Normally the project name is determined from the current
;; buffer. However, when we're switching projects, we want to
;; show the name of the project being switched to, rather than
;; the current project, in the minibuffer. This is a simple hack
;; to tell the `projectile-project-name' function to ignore the
;; current buffer and the caching mechanism, and just return the
;; value of the `projectile-project-name' variable.
(let ((projectile-project-name (funcall projectile-project-name-function
project-to-switch)))
(funcall switch-project-action)))
(run-hooks 'projectile-after-switch-project-hook)))
(if (file-directory-p project-to-switch)
(let ((switch-project-action (if arg
'projectile-commander
projectile-switch-project-action)))
(run-hooks 'projectile-before-switch-project-hook)
(let ((default-directory project-to-switch))
;; use a temporary buffer to load PROJECT-TO-SWITCH's dir-locals before calling SWITCH-PROJECT-ACTION
(with-temp-buffer
(hack-dir-local-variables-non-file-buffer))
;; Normally the project name is determined from the current
;; buffer. However, when we're switching projects, we want to
;; show the name of the project being switched to, rather than
;; the current project, in the minibuffer. This is a simple hack
;; to tell the `projectile-project-name' function to ignore the
;; current buffer and the caching mechanism, and just return the
;; value of the `projectile-project-name' variable.
(let ((projectile-project-name (funcall projectile-project-name-function
project-to-switch)))
(funcall switch-project-action)))
(run-hooks 'projectile-after-switch-project-hook))
(progn (projectile-remove-known-project project-to-switch)
(error "Directory %s does not exist" project-to-switch))))

;;;###autoload
(defun projectile-find-file-in-directory (&optional directory)
Expand Down

0 comments on commit 7000fc8

Please sign in to comment.