ben-gibson/GitLink

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

echarrod opened this issue · 3 comments

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?

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

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.

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.