diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index 611b4eb1..72e919d7 100644 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -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" } ] diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index 96d4c8b3..3299dd9f 100644 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -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" } ] diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index 611b4eb1..72e919d7 100644 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -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" } ] diff --git a/Default.sublime-commands b/Default.sublime-commands index 75b68451..70eeedbb 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -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" diff --git a/README.md b/README.md index 2efd45c4..a5343bf6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/git_gutter.py b/git_gutter.py index 68f6d3a3..6004b817 100644 --- a/git_gutter.py +++ b/git_gutter.py @@ -4,7 +4,8 @@ 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 @@ -12,7 +13,8 @@ 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 @@ -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': @@ -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( diff --git a/git_gutter_compare.py b/git_gutter_compare.py index c3bdd565..c5e5cda9 100644 --- a/git_gutter_compare.py +++ b/git_gutter_compare.py @@ -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: @@ -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): diff --git a/git_gutter_handler.py b/git_gutter_handler.py index 1734d10c..16f7318f 100644 --- a/git_gutter_handler.py +++ b/git_gutter_handler.py @@ -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,