Skip to content

Commit

Permalink
Ensure project-roots are directories
Browse files Browse the repository at this point in the history
Projectile adds projects as directory names, as in "~/project/".
Manually adding a project root that is not a directory name, as
in (projectile-add-known-project "~/project"), works fine, but
Projectile will then add the project root as a directory name, so that
both "~/project" and "~/project/" will be in the list of known
projects.

This change converts "~/project" to "~/project/" before adding it to
the list, thereby avoiding annoying near-duplicates.
  • Loading branch information
nickdrozd authored and bbatsov committed Jun 16, 2018
1 parent 2c344d5 commit d0b9c32
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -40,6 +40,7 @@
* [#987](https://github.com/bbatsov/projectile/issues/987): projectile-ag ignores ag-ignore-list when projectile-project-vcs is git
* [#1119](https://github.com/bbatsov/projectile/issues/1119): File search ignores non-root dirs if prefixed with "*"
* Treat members of `projectile-globally-ignored-file-suffixes` as file name suffixes (previous treat as file extensions).
* Ensure project roots are added as directory names to avoid near-duplicate projects, e.g. "~/project/" and "~/project".

### Bugs fixed

Expand Down
2 changes: 1 addition & 1 deletion projectile.el
Expand Up @@ -3635,7 +3635,7 @@ See `projectile-cleanup-known-projects'."
(unless (projectile-ignored-project-p project-root)
(setq projectile-known-projects
(delete-dups
(cons (abbreviate-file-name project-root)
(cons (file-name-as-directory (abbreviate-file-name project-root))
projectile-known-projects)))))

(defun projectile-load-known-projects ()
Expand Down
19 changes: 14 additions & 5 deletions test/projectile-known-project-test.el
Expand Up @@ -5,17 +5,26 @@
(ert-deftest projectile-test-add-known-project-adds-project-to-known-projects ()
"An added project should be added to the list of known projects."
(let (projectile-known-projects)
(projectile-add-known-project "~/my/new/project")
(projectile-add-known-project "~/my/new/project/")
(should (string= (car projectile-known-projects)
"~/my/new/project"))))
"~/my/new/project/"))))

(ert-deftest projectile-test-add-known-project-moves-projects-to-front-of-list ()
"adding a project should move it to the front of the list of known projects, if it already
existed."
(let ((projectile-known-projects (list "~/b" "~/a")))
(projectile-add-known-project "~/a")
(let ((projectile-known-projects (list "~/b/" "~/a/")))
(projectile-add-known-project "~/a/")
(should (equal projectile-known-projects
(list "~/a" "~/b")))))
(list "~/a/" "~/b/")))))

(ert-deftest projectile-test-add-known-project-no-near-duplicates ()
"~/project and ~/project/ should not be added
separately to the known projects list."
(let ((projectile-known-projects '("~/a/")))
(projectile-add-known-project "~/a")
(projectile-add-known-project "~/b")
(projectile-add-known-project "~/b/")
(should (equal projectile-known-projects '("~/b/" "~/a/")))))

(defun projectile-mock-serialization-functions (&rest body)
(let (projectile-serialization-calls)
Expand Down

0 comments on commit d0b9c32

Please sign in to comment.