Improves the handling of regular checked out repositories with worktrees to also handle bare repositories with worktrees.
Since a bare repository does not necessarily have a .git folder preceeding a worktrees folder, we must search for only a **/worktrees/** folder anywhere in the path.
Rather than using the first or last worktrees folder found, all matches are collected and a check is performed to see if there exists a HEAD file and a config file in the same parent folder as each worktrees folder.
The most deeply nested match is used, as it's less likely to find HEAD and config files inside a repository than it might be outside of the repository.
In my case, I clone a bare repository which by default names the folder as reponame.git, and so the original RegExp was catching the .git/worktrees out of the path reponame.git/worktrees and ended up creating a path like reponame/.git/config which didn't exist.
Improves the handling of regular checked out repositories with worktrees to also handle bare repositories with worktrees.
Since a bare repository does not necessarily have a
.git
folder preceeding aworktrees
folder, we must search for only a**/worktrees/**
folder anywhere in the path.Rather than using the first or last
worktrees
folder found, all matches are collected and a check is performed to see if there exists aHEAD
file and aconfig
file in the same parent folder as eachworktrees
folder.The most deeply nested match is used, as it's less likely to find
HEAD
andconfig
files inside a repository than it might be outside of the repository.I believe this addresses the problem mentioned in the comment of this closed issue https://github.com/ziyasal/vscode-open-in-github/issues/111#issuecomment-1182140935 which is the same error I was seeing.
In my case, I clone a bare repository which by default names the folder as
reponame.git
, and so the original RegExp was catching the.git/worktrees
out of the pathreponame.git/worktrees
and ended up creating a path likereponame/.git/config
which didn't exist.I'm happy to address any feedback!