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

commands that link to github are all 404 because absolute path #80

Closed farzher closed 9 years ago

farzher commented 9 years ago

You're linking me to here image why is that an absolute path to my C drive?

The page is of course a 404 image

bgreenlee commented 9 years ago

Hi @farzher – this is hard for me to troubleshoot remotely. It looks like you're a developer, so if you don't mind poking around in the code, the relevant bit is here.

What it does is this:

  1. runs git ls-remote --get-url to get your remote repository location. For sublime-github, this is "git@github.com:bgreenlee/sublime-github.git".
  2. It does some munging (lines 424-430) to turn that into a url, e.g. "https://github.com/bgreenlee/sublime-github"
  3. It then runs git rev-parse --show-toplevel to get the filesystem path to your repository. For example, for my sublime-github repo on my laptop, this is "/Users/brad/Library/Application Support/Sublime Text 3/Packages/sublime-github"
  4. It then runs git rev-parse --abbrev-ref HEAD to get the name of the branch you are on.
  5. Line 442 could be where things start going sideways for you. It tries to figure out the path of the file you're looking at in Sublime Text relative to the root of your repository by getting the full path to the file you are looking at and splitting on the toplevel_path it got in step 3.
  6. (You can ignore lines 444-457, those are just trying to figure out if you have any lines selected)
  7. Line 459 takes all the pieces it calculated in steps 1-5 and puts them together to get the url it will go to.

So based on what I can see in your url, it seems like there's some mismatch between the path it gets to your repository by doing git rev-parse --show-toplevel and the path that Sublime Text returns for the file you're on. You can see what Sublime Text is returning by just opening the console (ctrl-) and typing:view.file_name()`

If you're uncomfortable making the fixes yourself and submitting a pull request, I can try to figure it out if you can give me the output for the various git and sublime commands I listed above. Feel free to email me directly if you don't want to post those here (my email is on my profile page)

farzher commented 9 years ago

Cool, sounds pretty straight forward. I'll check it out

gmce93 commented 8 years ago

It appears as though this bug is still occurring if the project in Sublime is running on a symlinked folder. Running git rev-parse --show-toplevel gives me the literal path rather than the symlink'd path, so I presume that's causing my GitHub URL generation to be wrong? I've just installed the plugin and it appears to be on the latest version.