ben-gibson / GitLink

A Jetbrains plugin that opens a local file under Git version control in its remote host using the default browser.
https://plugins.jetbrains.com/plugin/8183-gitlink
MIT License
671 stars 58 forks source link

Incorrectly assuming main branch name when loading from a branch that isn't pushed #266

Open echarrod opened 1 year ago

echarrod commented 1 year ago

If I am on a branch which is not pushed, with a commit on it, the link generated is:

https://gitlab.com/my-company/my-group/my-repo/blob/main/.gitmodules#L1-1

When this should instead be (for my repo):

https://gitlab.com/my-company/my-group/my-repo/blob/master/.gitmodules#L1-1

Is it possible to look up what the main branch is, so that it can be correctly loaded, in the event that the local branch is not present on origin?

echarrod commented 1 year ago

I found the Fallback branch option now, but is it possible to load this dynamically instead of having to specify it?

ben-gibson commented 1 year ago

It may be possible to do something a little more clever than it currently does. But it would only really work if the branches were named something standard like master or main, otherwise it would have no way to know which branch to look for. This is a nice suggestion though, it might be something that gets added in the future.

benediktwerner commented 1 year ago

You can check the remote head to determine what the remote considers the default branch: git rev-parse --abbrev-ref origin/HEAD. This unfortunately isn't set if the remote was added manually but it is set for the remote a repo was cloned from. It can also be fetched using git remote set-head origin --auto.