Skip to content

Commit

Permalink
Use git root instead of folder root for running git commands
Browse files Browse the repository at this point in the history
  • Loading branch information
predrag-codetribe committed Oct 26, 2019
1 parent 69bcd6e commit eea64da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions core/Command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Command:

def __init__(self, window):
self.window = window
self.project_root = window.extract_variables()['folder']
self.project_root = None
self.project_root = self.run(['git rev-parse --show-toplevel']).strip()

def git_statuses(self):
''' Return a list of git statuses.
Expand Down Expand Up @@ -62,7 +63,7 @@ def git_statuses(self):
"old_file_name": old_file_name
})

statuses = sorted(statuses, key=lambda k: k['file_name'])
statuses = sorted(statuses, key=lambda k: k['file_name'])

return statuses

Expand Down Expand Up @@ -130,9 +131,16 @@ def escape_special_characters(self, file_name):
return file_name.replace(' ', '\\ ')

def run(self, cmd):
cwd = None

if self.project_root is None:
cwd = self.window.extract_variables()['folder']
else:
cwd = self.project_root

p = subprocess.Popen(cmd,
bufsize=-1,
cwd=self.project_root,
cwd=cwd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down
5 changes: 3 additions & 2 deletions status_commands/GotoFileCommand.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from os import path
from GitDiffView.status_commands.GitTextCommand import GitTextCommand
from GitDiffView.core.Command import Command


class GitDiffViewGotoFileCommand(GitTextCommand):
Expand All @@ -11,8 +12,8 @@ def run(self, edit):
print('cant go to a deleted file')
return

project_root = self.window.extract_variables()['folder']
absolute_path_to_file = path.join(project_root,
command = Command(self.window)
absolute_path_to_file = path.join(command.project_root,
file["file_name"])
self.window.run_command('toggle_git_diff_view')
view = self.window.open_file(absolute_path_to_file)
Expand Down

0 comments on commit eea64da

Please sign in to comment.