bugthesystem / vscode-open-in-github

Extension for Visual Studio Code which can be used to jump to a source code line in Github, Bitbucket, GitLab and Visualstudio.com
MIT License
197 stars 73 forks source link

Add handling for bare repositories that use worktrees #151

Closed iferc closed 1 year ago

iferc commented 1 year ago

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.

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 path reponame.git/worktrees and ended up creating a path like reponame/.git/config which didn't exist.

I'm happy to address any feedback!