sshaw / git-link

Emacs package to get the GitHub/Bitbucket/GitLab/... URL for a buffer location
399 stars 74 forks source link

Only hexify branch name if it's not nil. #127

Closed mijoharas closed 3 months ago

mijoharas commented 3 months ago

When we pass the branch name through to the handler, we do this https://github.com/sshaw/git-link/blob/master/git-link.el#L864 that calls url-hexify-string on the branch, whether it's nil or not. Passing a nil branch through to it will give "" which is truthy, which means that the (or branch commit) line in each of the handlers, e.g.: https://github.com/sshaw/git-link/blob/master/git-link.el#L594 will always evaluate to the truth-ey empty string "" and will give an incorrect url.

Fix that by only calling url-hexify-string if the branch is non-nil already.

sshaw commented 3 months ago

Thanks.

How can I reproduce this issue?

Even though we don't call url-hexify-string the format string "%s" still exists so won't that get interpolated with nil anyways?

mijoharas commented 3 months ago

hey, so, I just called git-link on a commit that wasn't part of a branch. i.e. from this commit, we do git checkout HEAD~1:

and then when calling git-link I get something like https://github.com/sshaw/git-link/blob//README.md?plain=1#L1 (which is a link that doesn't exist) instead of the expected https://github.com/sshaw/git-link/blob/0acdfd6152fad132cecf25f6971c7f6b430dca15/README.md?plain=1#L1 (i.e. yes, %s gets interpolated with nil but that leads to an invalid url, rather than a correct one with the fix).

sshaw commented 3 months ago

Oh yes, I see. Thank you!

mijoharas commented 2 months ago

ahhh, sorry should have checked the issues, could have linked to them myself :sweat_smile: (went straight to the code to just figure out what was wrong). Thanks again :raised_hands: