From 66e7426925799f2beb06b91857a9ef83fd241074 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Mon, 1 Feb 2016 14:50:24 -0600 Subject: [PATCH] Pass through the git_root_dir, if present Otherwise the file > blame > commit sequence breaks. --- git/__init__.py | 20 +++++++++++++------- git/history.py | 4 +--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/git/__init__.py b/git/__init__.py index f8024182..e1886a11 100644 --- a/git/__init__.py +++ b/git/__init__.py @@ -319,7 +319,11 @@ def quick_panel(self, *args, **kwargs): def record_git_root_to_view(self, view): # Store the git root directory in the view so we can resolve relative paths # when the user wants to navigate to the source file. - view.settings().set("git_root_dir", git_root(self.get_working_dir())) + if self.get_working_dir(): + root = git_root(self.get_working_dir()) + else: + root = self.active_view().settings().get("git_root_dir") + view.settings().set("git_root_dir", root) # A base for all git commands that work with the entire repository @@ -359,11 +363,10 @@ def get_working_dir(self): file_name = self._active_file_name() if file_name: return os.path.realpath(os.path.dirname(file_name)) - else: - try: # handle case with no open folder - return self.window.folders()[0] - except IndexError: - return '' + try: # handle case with no open folder + return self.window.folders()[0] + except IndexError: + return '' def get_window(self): return self.window @@ -390,7 +393,10 @@ def get_relative_file_name(self): return file_name.replace('\\', '/') # windows issues def get_working_dir(self): - return os.path.realpath(os.path.dirname(self.view.file_name())) + file_name = self.view.file_name() + if file_name: + return os.path.realpath(os.path.dirname(file_name)) + return '' def get_window(self): # Fun discovery: if you switch tabs while a command is working, diff --git a/git/history.py b/git/history.py index 83e9acd5..9a0ef271 100644 --- a/git/history.py +++ b/git/history.py @@ -43,8 +43,6 @@ def get_lines(self): def blame_done(self, result, position=None): view = self.scratch(result, title="Git Blame", position=position, syntax=plugin_file("syntax/Git Blame.tmLanguage")) - # store working dir to be potentially used by the GitGotoCommit command - view.settings().set("git_working_dir", self.get_working_dir()) class GitLog(object): @@ -239,7 +237,7 @@ def run(self, edit): commit = line.split(" ")[0] if not commit or commit == "00000000": return - working_dir = view.settings().get("git_working_dir") + working_dir = view.settings().get("git_root_dir") self.run_command(['git', 'show', commit], self.show_done, working_dir=working_dir) def show_done(self, result):