dacap/sublime-text-2-git — pull request #3 by vanrijn (2013-03-21 20:58:48+00:00)
Title: Fix incorrect assumption that git_root_dir is populated and allow GitGot...

...oDiff to work with Git Custom commands

I think "git_root_dir" is set to the project root, not the actual git root directory. I was seeing this backtrace from GitGotoDiff when I opened a new project window:

Traceback (most recent call last):
File "./sublime_plugin.py", line 362, in run_
File "./diff.py", line 129, in run
file_name = os.path.join(v.settings().get("git_root_dir"), file_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.py", line 67, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

So I added a check to make sure that "git_root_dir" is valid before trying to combine it with file_name. That prevents the errors and still allows ST to open the file correctly.

I think there may be a bug in the Git plugin's "git_root_dir" value, but that's a different issue that I'll track separately.

I also wanted to fix the problem I reported at https://github.com/kemayo/sublime-text-2-git/issues/256 where I wanted to be able to run a git custom command of "git diff master" and then be able to navigate that diff via GitGotoDiff. This wasn't previously possible because GitGotoDiff was returning immediately if the view name wasn't "Git Diff". I think the better way to do this is to check the view's scope_name and make sure it's what we expect. Namely, it should be "markup.inserted.diff" or "markup.deleted.diff", just as it is in the keymap file context.

I tested this change by using the normal "Git Diff All" command and also doing a "Git Custom Command" with "diff master" as the arguments. I then pressed Enter in the +++ and --- lines in the resultant tab and buffer and verified that GitGotoDiff operated correctly in both scenarios.

HTH! =:)