Skip to content

Commit

Permalink
Merge pull request #694 from divmain/randy3k/compare_head
Browse files Browse the repository at this point in the history
compare commits related enhancements
  • Loading branch information
divmain committed Jul 18, 2017
2 parents 2e5bae0 + b7359f0 commit f9df84a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
8 changes: 8 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,14 @@
{ "key": "setting.git_savvy.compare_commit_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["F"],
"command": "gs_compare_commit_show_diff",
"args": { "reverse": true },
"context": [
{ "key": "setting.git_savvy.compare_commit_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["r"],
"command": "gs_compare_commit_refresh",
Expand Down
68 changes: 45 additions & 23 deletions core/commands/commit_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GsCompareCommitCommand(WindowCommand, GitCommand):
"""

def run(self, base_commit, target_commit=None, file_path=None, title=None):
self.base_commit = base_commit
self.base_commit = base_commit or "HEAD"
self.target_commit = target_commit or "HEAD"
self._file_path = file_path
self.title = title or "COMMIT COMPARISON"
Expand Down Expand Up @@ -88,26 +88,36 @@ class GsCompareCommitShowDiffCommand(TextCommand, GitCommand):
Refresh view of all commits diff between branches.
"""

def run(self, edit):
def run(self, edit, reverse=False):
self._reverse = reverse
sublime.set_timeout_async(self.run_async)

def run_async(self):
base_commit = self.view.settings().get("git_savvy.compare_commit_view.base_commit")
target_commit = self.view.settings().get("git_savvy.compare_commit_view.target_commit")
file_path = self.file_path
self.view.window().run_command("gs_diff", {
"base_commit": base_commit,
"target_commit": target_commit,
"file_path": file_path,
"disable_stage": True,
"title": "DIFF: {}..{}".format(base_commit, target_commit)
})
if self._reverse:
self.view.window().run_command("gs_diff", {
"base_commit": target_commit,
"target_commit": base_commit,
"file_path": file_path,
"disable_stage": True,
"title": "DIFF: {}..{}".format(target_commit, base_commit)
})
else:
self.view.window().run_command("gs_diff", {
"base_commit": base_commit,
"target_commit": target_commit,
"file_path": file_path,
"disable_stage": True,
"title": "DIFF: {}..{}".format(base_commit, target_commit)
})


class GsCompareAgainstReferenceCommand(WindowCommand, GitCommand):
def run(self, target_commit=None, file_path=None):
def run(self, base_commit=None, file_path=None):
self._file_path = file_path
self._target_commit = target_commit
self._base_commit = base_commit
sublime.set_timeout_async(self.run_async)

def run_async(self):
Expand All @@ -116,21 +126,21 @@ def run_async(self):
def show_diff(self, ref):
self.window.run_command("gs_compare_commit", {
"file_path": self._file_path,
"base_commit": ref,
"target_commit": self._target_commit
"target_commit": ref,
"base_commit": self._base_commit
})

def on_cancel(self):
self.window.run_command("gs_compare_against", {
"target_commit": self._target_commit,
"base_commit": self._base_commit,
"file_path": self._file_path
})


class GsCompareAgainstBranchCommand(WindowCommand, GitCommand):
def run(self, target_commit=None, file_path=None):
def run(self, base_commit=None, file_path=None):
self._file_path = file_path
self._target_commit = target_commit
self._base_commit = base_commit
sublime.set_timeout_async(self.run_async)

def run_async(self):
Expand All @@ -151,15 +161,15 @@ def run_async(self):
def on_branch_selection(self, index):
if index == -1:
self.window.run_command("gs_compare_against", {
"target_commit": self._target_commit,
"base_commit": self._base_commit,
"file_path": self._file_path
})
return
self._selected_branch = self.all_branches[index]
self.window.run_command("gs_compare_commit", {
"file_path": self._file_path,
"base_commit": self._selected_branch,
"target_commit": self._target_commit
"target_commit": self._selected_branch,
"base_commit": self._base_commit
})


Expand All @@ -169,19 +179,31 @@ class GsCompareAgainstCommand(PanelActionMixin, WindowCommand, GitCommand):
["compare_against_reference", "Reference"],
]

def run(self, target_commit=None, file_path=None, current_file=False):
def run(self, base_commit=None, file_path=None, current_file=False):
self._file_path = self.file_path if current_file else file_path
self._target_commit = target_commit
self._base_commit = base_commit
super().run()

def update_actions(self):
super().update_actions()
if self._base_commit:
self.actions = [["compare_against_head", "HEAD"]] + self.actions

def compare_against_branch(self):
self.window.run_command("gs_compare_against_branch", {
"target_commit": self._target_commit,
"base_commit": self._base_commit,
"file_path": self._file_path
})

def compare_against_reference(self):
self.window.run_command("gs_compare_against_reference", {
"target_commit": self._target_commit,
"base_commit": self._base_commit,
"file_path": self._file_path
})

def compare_against_head(self):
self.window.run_command("gs_compare_commit", {
"base_commit": self._base_commit,
"target_commit": "HEAD",
"file_path": self._file_path
})
2 changes: 1 addition & 1 deletion core/commands/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def checkout_commit(self):

def compare_against(self):
self.window.run_command("gs_compare_against", {
"target_commit": self._commit_hash,
"base_commit": self._commit_hash,
"file_path": self._file_path
})

Expand Down
1 change: 1 addition & 0 deletions popups/compare_commit_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h3>Actions</h3>
<li><code><span class="shortcut-key">.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>go to next commit</code></li>
<li><code><span class="shortcut-key">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>go to previous commit</code></li>
<li><code><span class="shortcut-key">f&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>show commits diff</code></li>
<li><code><span class="shortcut-key">F&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>show commits diff (reversed)</code></li>
</ul>

<h3>Other</h3>
Expand Down

0 comments on commit f9df84a

Please sign in to comment.