Support git worktrees

Simple change that also accepts `.git` *files*, instead of only `.git`
directories, as indicating valid git projects. This is a cheap way (i.e. low
performance cost) to detect git worktree repos.

Closes #11
This commit is contained in:
Marcin S 2022-07-25 20:17:02 +02:00
parent 3a85c415b2
commit bb8f205bad
No known key found for this signature in database
GPG Key ID: 68A476F4791BB6B3
1 changed files with 5 additions and 1 deletions

View File

@ -474,7 +474,7 @@ If MAX-DEPTH is set to nil, do not use any recursion stop gap."
(let ((full-file (concat dir "/" file)))
;; Don't follow symlinks to other directories.
(when (not (file-symlink-p full-file))
(if (file-directory-p (concat full-file ".git"))
(if (my-repo-pins--is-git-dir full-file)
;; It's a git repo, let's stop here.
(setq projects (nconc projects (list full-file)))
;; It's not a git repo, let's recurse into it.
@ -502,6 +502,10 @@ If MAX-DEPTH is set to nil, do not use any recursion stop gap."
(recurse-in-dir dir 0)
(recurse-in-dir dir nil))))
(defun my-repo-pins--is-git-dir (dir)
"Return non-nil if DIR is a git directory."
(file-exists-p (concat (file-name-as-directory dir) ".git")))
(defun my-repo-pins--get-code-root-projects (code-root max-depth)
"Retrieve the projects contained in the CODE-ROOT directory.
We're going to make some hard assumptions about how the