bgreenlee / sublime-github

Sublime Text 2/3 plugin that provides a number of useful commands for GitHub.
MIT License
455 stars 98 forks source link

Get permalinks for the local HEAD not the HEAD of the remote branch #119

Open wearhere opened 5 years ago

wearhere commented 5 years ago

On GitHub, permalinks reference the HEAD of the remote branch since that’s what you’re looking at when you request the permalink (https://help.github.com/en/articles/getting-permanent-links-to-files). In Sublime, it makes more sense for permalinks to reference your local HEAD since that’s what you’re looking at when you run a permalink command.

Referencing the local HEAD lets the user run permalink commands with a commit checked out rather than a branch; or having checked out a branch that they've just created, if the user has neither added commits to that branch nor pushed the branch to the remote.

If the user has added commits to such a branch without pushing them to the remote, then the link will 404 on GitHub. Then again, previously, if the user had pushed the branch to the remote—just not the most recent commits on the branch—then we would have created an out-of-date permalink, and this would arguably have been a worse failure because it would be silent.

At some future point, it might be nice to detect, locally, if a permalink was going to 404, and show an error message before the user went to GitHub.

Referencing the local HEAD also fixes a bug in the previous implementation where we’d only successfully fetch the remote HEAD if the name of the remote branch was exactly the same as the local branch, since we executed git rev-parse <remote_branch> at line 508 without prefixing remote_branch with the name of the remote.

Tests:

bgreenlee commented 2 years ago

Hi! I'm so sorry it has taken me years to respond to you. If you're still interested in this would you mind testing it again against the latest HEAD and fixing the minor conflict in the README?

(I know I've neglected this repo...I haven't used Sublime Text in years. :( )