Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try harder to get the git root directory the first time GitGotoDiff is called #524

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def git_root_exist(directory):
return git_root(directory)


# try to get an open folder from the window
def get_open_folder_from_window(window):
try: # handle case with no open folder
return window.folders()[0]
except IndexError:
return ''


def view_contents(view):
region = sublime.Region(0, view.size())
return view.substr(region)
Expand Down Expand Up @@ -392,10 +400,7 @@ def get_working_dir(self):
file_name = self.active_file_path()
if file_name:
return os.path.realpath(os.path.dirname(file_name))
try: # handle case with no open folder
return self.window.folders()[0]
except IndexError:
return ''
return get_open_folder_from_window(self.window)

def get_window(self):
return self.window
Expand Down
6 changes: 5 additions & 1 deletion git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sublime_plugin
import os
import re
from . import GitTextCommand, GitWindowCommand, do_when, goto_xy
from . import GitTextCommand, GitWindowCommand, do_when, goto_xy, git_root, get_open_folder_from_window


class GitDiff (object):
Expand Down Expand Up @@ -99,6 +99,10 @@ def run(self, edit):
self.goto_line = int(hunk_start_line) + line_offset - 1

git_root_dir = v.settings().get("git_root_dir")
# See if we can get the git root directory if we haven't saved it yet
if not git_root_dir:
working_dir = get_open_folder_from_window(v.window())
git_root_dir = git_root(working_dir) if working_dir else None

# Sanity check and see if the file we're going to try to open even
# exists. If it does not, prompt the user for the correct base directory
Expand Down