Skip to content

Add button to show the commit in full #9

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

Merged
merged 2 commits into from
Jul 7, 2017
Merged
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
48 changes: 40 additions & 8 deletions git-blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
template = '''
<span>
{scheme}
<strong>Git Blame:</strong> ({user})
&nbsp;<strong>Git Blame:</strong> ({user})
Updated: {date} {time} |
<a href="copy-{sha}">[{sha}]</a> |
<a href="close">
<close>&#10006;</close>&nbsp;
</a>
{sha}
<a href="copy-{sha}">[Copy]</a>
<a href="show-{sha}">[Show]</a>
<a href="close"><close>[X]</close></a>&nbsp;
</span>
'''

Expand Down Expand Up @@ -82,10 +82,32 @@ def parse_blame(self, blame):

return(sha, user[1:], date, time)

def get_commit(self, sha, path):
try:
return shell(["git", "show", sha],
cwd=os.path.dirname(os.path.realpath(path)),
startupinfo=si)
except Exception as e:
return

def on_phantom_close(self, href):
if href.startswith('copy'):
sha = href.replace('copy-','')
sublime.set_clipboard(sha)
href_parts = href.split('-')

if len(href_parts) > 1:
intent = href_parts[0]
sha = href_parts[1]
# The SHA output by git-blame may have a leading caret to indicate
# that it is a "boundary commit". That useful information has
# already been shown in the phantom, so strip it before going on to
# use the SHA programmatically.
sha = sha.strip('^')

if intent == "copy":
sublime.set_clipboard(sha)
elif intent == "show":
desc = self.get_commit(sha, self.view.file_name()).decode('utf-8')
buf = self.view.window().new_file()
buf.run_command('insert_commit_description', {'desc': desc})

self.view.erase_phantoms('git-blame')

Expand Down Expand Up @@ -114,3 +136,13 @@ def run(self, edit):
phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close)
phantoms.append(phantom)
self.phantom_set.update(phantoms)


class InsertCommitDescriptionCommand(sublime_plugin.TextCommand):

def run(self, edit, desc):
view = self.view
view.set_scratch(True)
view.set_syntax_file('Packages/Diff/Diff.sublime-syntax')
view.insert(edit, 0, desc)