From bb8f205bad176357441e6237c5488158d7fc64a2 Mon Sep 17 00:00:00 2001 From: Marcin S Date: Mon, 25 Jul 2022 20:17:02 +0200 Subject: [PATCH] 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 --- my-repo-pins.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/my-repo-pins.el b/my-repo-pins.el index 097ce1e..f493ee1 100644 --- a/my-repo-pins.el +++ b/my-repo-pins.el @@ -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