Get permalinks for the local HEAD not the HEAD of the remote branch #119
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 prefixingremote_branch
with the name of the remote.Tests:
pushed to the remote
has not been pushed to the remote
checked out rather than a branch
has been pushed to the remote
out vs. a branch
out and the user has not pushed that branch but has also not added commits
to that branch
if the user has added commits to a branch and not pushed them to GitHub