diff --git a/Default.sublime-commands b/Default.sublime-commands index 30f0d7d4..f8b0c04a 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -6,6 +6,10 @@ "caption": "Git: Blame", "command": "git_blame" } + ,{ + "caption": "Git: WTF", + "command": "git_wtf" + } ,{ "caption": "Git: Document Selection", "command": "git_document" diff --git a/git/history.py b/git/history.py index ccb959a9..f0832b35 100644 --- a/git/history.py +++ b/git/history.py @@ -51,6 +51,29 @@ def blame_done(self, result, focused_line=1): ) +class GitWtfCommand(GitBlameCommand): + def run(self, edit): + command = ['git', 'log'] + line_ranges = [self.get_lines(selection) for selection in self.view.sel() if not selection.empty()] + + if line_ranges: + for line_range in line_ranges: + command.extend( + ('-L', str(line_range[0]) + ',' + str(line_range[1]) + ':' + self.get_file_name()) + ) + else: + command.extend(('--follow', '--')) + command.append(self.get_file_name()) + + self.run_command(command, self.wtf_done) + + def wtf_done(self, result): + self.scratch( + result, title="Git WTF", + syntax=plugin_file("syntax/Git Commit View.tmLanguage") + ) + + class GitLog(object): def run(self, edit=None): fn = self.get_file_name()