diff --git a/Default.sublime-commands b/Default.sublime-commands index b822ade2..e9be4321 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -81,6 +81,14 @@ "caption": "Git: Diff Tool All", "command": "git_raw", "args": { "command": "git difftool", "may_change_files": false } } + ,{ + "caption": "Git: Diff Branch", + "command": "git_diff_branch" + } + ,{ + "caption": "Git: Diff Current File with Branch", + "command": "git_diff_branch", "args": { "current_file": true } + } ,{ "caption": "Git: Commit", "command": "git_commit" diff --git a/diff.py b/diff.py index f1e5edfb..2283e5fd 100644 --- a/diff.py +++ b/diff.py @@ -56,6 +56,31 @@ class GitDiffCommitCommand(GitDiffCommit, GitWindowCommand): pass +class GitDiffBranchCommand(GitDiff, GitWindowCommand): + may_change_files = False + on_file = [] + + def run(self, edit=None, ignore_whitespace=False, current_file=False): + self.ignore_whitespace = ignore_whitespace + if current_file and self._active_file_name(): + self.on_file = ['--', self._active_file_name()] + self.run_command(['git', 'branch', '--no-color'], self.branch_done) + + def branch_done(self, result): + self.results = result.rstrip().split('\n') + self.quick_panel(self.results, self.panel_done, + sublime.MONOSPACE_FONT) + + def panel_done(self, picked): + if 0 > picked < len(self.results): + return + picked_branch = self.results[picked].strip() + command = ['git', 'diff', '--no-color'] + if self.ignore_whitespace: + command.extend(('--ignore-all-space', '--ignore-blank-lines')) + self.run_command(command + ['..'+picked_branch] + self.on_file, self.diff_done) + + class GitGotoDiff(sublime_plugin.TextCommand): def __init__(self, view): self.view = view