Subject: 29.2; project root directory is wrong for submodules of worktrees

From: Patrick Bader <[email-masked]>
Date: Mon, 4 Mar 2024 16:21:48 +0100

Hi,

when navigating to a file in a git submodule, the project root stays in 
the parent repository.
If the submodule is part of a git worktree, however, this does not work 
as expected and the project root switches to the directory of the 
submodule itself.

The issue seems to be how project--submodule-p is checking whether the 
current repository is a submodule.
In the worktree case, there is the worktree path between the .git and 
modules directory in the gitfile.
There may also be regular directory names before the .git directory 
apart of "../".

I have attached a patch to fix this.

Best,

Patrick

From 5fca51b5d5205b6b3c832246ee5f2cba1af697c0 Mon Sep 17 00:00:00 2001
From: Patrick Bader <[email-masked]>
Date: Mon, 4 Mar 2024 16:14:25 +0100
Subject: [PATCH] fix: project submodule detection does not work for worktrees

---
 lisp/progmodes/project.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 9622b1b6768..2eddda0a67c 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -602,7 +602,7 @@ See `project-vc-extra-root-markers' for the marker value format.")
         (goto-char (point-min))
         ;; Kind of a hack to distinguish a submodule from
         ;; other cases of .git files pointing elsewhere.
-        (looking-at "gitdir: [./]+/\\.git/modules/"))
+        (looking-at "gitdir: .+/\\.git/\\(worktrees/.*\\)?modules/"))
       t)
      (t nil))))

base-commit: 5b49a38d1b37707bbbc8c069ed20ce7cd18fb2ac
-- 
2.44.0