Skip to content

Commit

Permalink
Add 'Compare against file commit' and enable filtering by commit id (…
Browse files Browse the repository at this point in the history
…Issue #281)
  • Loading branch information
deathaxe committed Dec 3, 2016
1 parent e3642b3 commit c6c8e90
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ "keys": ["ctrl+shift+alt+c", "h"], "command": "git_gutter_compare_head" },
{ "keys": ["ctrl+shift+alt+c", "o"], "command": "git_gutter_compare_origin" },
{ "keys": ["ctrl+shift+alt+c", "c"], "command": "git_gutter_compare_commit" },
{ "keys": ["ctrl+shift+alt+c", "f"], "command": "git_gutter_compare_file_commit" },
{ "keys": ["ctrl+shift+alt+c", "b"], "command": "git_gutter_compare_branch" },
{ "keys": ["ctrl+shift+alt+c", "t"], "command": "git_gutter_compare_tag" }
]
1 change: 1 addition & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ "keys": ["super+shift+option+c", "h"], "command": "git_gutter_compare_head" },
{ "keys": ["super+shift+option+c", "o"], "command": "git_gutter_compare_origin" },
{ "keys": ["super+shift+option+c", "c"], "command": "git_gutter_compare_commit" },
{ "keys": ["super+shift+option+c", "f"], "command": "git_gutter_compare_file_commit" },
{ "keys": ["super+shift+option+c", "b"], "command": "git_gutter_compare_branch" },
{ "keys": ["super+shift+option+c", "t"], "command": "git_gutter_compare_tag" }
]
1 change: 1 addition & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ "keys": ["ctrl+shift+alt+c", "h"], "command": "git_gutter_compare_head" },
{ "keys": ["ctrl+shift+alt+c", "o"], "command": "git_gutter_compare_origin" },
{ "keys": ["ctrl+shift+alt+c", "c"], "command": "git_gutter_compare_commit" },
{ "keys": ["ctrl+shift+alt+c", "f"], "command": "git_gutter_compare_file_commit" },
{ "keys": ["ctrl+shift+alt+c", "b"], "command": "git_gutter_compare_branch" },
{ "keys": ["ctrl+shift+alt+c", "t"], "command": "git_gutter_compare_tag" }
]
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"caption": "GitGutter: Compare Against Commit",
"command": "git_gutter_compare_commit"
},
{
"caption": "GitGutter: Compare Against File Commit",
"command": "git_gutter_compare_file_commit"
},
{
"caption": "GitGutter: Compare Against Branch",
"command": "git_gutter_compare_branch"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ By default, Git Gutter compares your working copy against the HEAD. You can chan
- Compare against particular branch
- Compare against particular tag
- Compare against specific commit
- Compare against specific file commit (current file's history)

To change the compare option:

- Open the command palette (`Ctrl-Shift-P` for Windows/Linux, `Cmd-Shift-P` for Mac)
- Start typing `GitGutter`
- You'll see the 4 options listed above, select one with the keyboard.
- You'll see the 5 options listed above, select one with the keyboard.
- Choose the branch/tag/commit to compare against.

### Jumping Between Changes
Expand Down
14 changes: 12 additions & 2 deletions git_gutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
from .git_gutter_handler import GitGutterHandler
from .git_gutter_compare import (
GitGutterCompareCommit, GitGutterCompareBranch, GitGutterCompareTag,
GitGutterCompareHead, GitGutterCompareOrigin, GitGutterShowCompare)
GitGutterCompareHead, GitGutterCompareOrigin, GitGutterShowCompare,
GitGutterCompareFileCommit)
from .git_gutter_jump_to_changes import GitGutterJumpToChanges
from .git_gutter_popup import show_diff_popup
from .git_gutter_show_diff import GitGutterShowDiff
except (ImportError, ValueError):
from git_gutter_handler import GitGutterHandler
from git_gutter_compare import (
GitGutterCompareCommit, GitGutterCompareBranch, GitGutterCompareTag,
GitGutterCompareHead, GitGutterCompareOrigin, GitGutterShowCompare)
GitGutterCompareHead, GitGutterCompareOrigin, GitGutterShowCompare,
GitGutterCompareFileCommit)
from git_gutter_jump_to_changes import GitGutterJumpToChanges
from git_gutter_popup import show_diff_popup
from git_gutter_show_diff import GitGutterShowDiff
Expand Down Expand Up @@ -52,6 +54,8 @@ def _handle_subcommand(self, **kwargs):
GitGutterJumpToChanges(self.git_handler).jump_to_prev_change()
elif action == 'compare_against_commit':
GitGutterCompareCommit(self.git_handler).run()
elif action == 'compare_against_file_commit':
GitGutterCompareFileCommit(self.git_handler).run()
elif action == 'compare_against_branch':
GitGutterCompareBranch(self.git_handler).run()
elif action == 'compare_against_tag':
Expand Down Expand Up @@ -97,6 +101,12 @@ def run(self, edit):
'git_gutter', {'action': 'compare_against_commit'})


class GitGutterCompareFileCommitCommand(TextCommand):
def run(self, edit):
self.view.run_command(
'git_gutter', {'action': 'compare_against_file_commit'})


class GitGutterCompareBranchCommand(TextCommand):
def run(self, edit):
self.view.run_command(
Expand Down
13 changes: 12 additions & 1 deletion git_gutter_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def parse_commits(results):
return self.git_handler.git_commits().then(parse_commits)

def item_to_commit(self, item):
return item[1].split(' ')[0]
return item[0].split(' \u00BB ')[0]

def _show_quick_panel(self, results):
if results:
Expand All @@ -34,6 +34,17 @@ def _on_select(self, results, selected):
self.git_handler.set_compare_against(commit)


class GitGutterCompareFileCommit(GitGutterCompareCommit):
def commit_list(self):
def parse_file_commits(results):
if results:
return [r.split('\a', 2) for r in results.splitlines()]
sublime.message_dialog(
'No commits with reference to the file found in repository.')
return []
return self.git_handler.git_file_commits().then(parse_file_commits)


class GitGutterCompareBranch(GitGutterCompareCommit):
def commit_list(self):
def parse_branches(results):
Expand Down
14 changes: 13 additions & 1 deletion git_gutter_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,23 @@ def git_commits(self):
'--git-dir=' + self.git_dir,
'--work-tree=' + self.git_tree,
'log', '--all',
'--pretty=%s\a%h %an <%aE>\a%ad (%ar)',
'--pretty=%h \u00BB %s\a%an <%aE>\a%ad (%ar)',
'--date=local', '--max-count=9000'
]
return GitGutterHandler.run_command(args)

def git_file_commits(self):
args = [
settings.git_binary_path,
'--git-dir=' + self.git_dir,
'--work-tree=' + self.git_tree,
'log',
'--pretty=%h \u00BB %s\a%an <%aE>\a%ad (%ar)',
'--date=local', '--max-count=9000',
'--', self.git_path
]
return GitGutterHandler.run_command(args)

def git_branches(self):
args = [
settings.git_binary_path,
Expand Down

0 comments on commit c6c8e90

Please sign in to comment.