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

"git wtf" command: get a history of the current selection #547

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"caption": "Git: Blame",
"command": "git_blame"
}
,{
"caption": "Git: WTF",
"command": "git_wtf"
}
,{
"caption": "Git: Document Selection",
"command": "git_document"
Expand Down
23 changes: 23 additions & 0 deletions git/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down