Skip to content

Commit

Permalink
Enhancement: git revert
Browse files Browse the repository at this point in the history
Added to
  - Command pallet
  - Git log -> Commit action
  - Git graph -> Commit action

closes #732
  • Loading branch information
stoivo committed Aug 20, 2017
1 parent 7d16c8d commit 81a7624
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@
"command": "gs_log",
"args": { "current_file": true }
},
{
"caption": "git: revert",
"command": "gs_log_revert_commit"
},
{
"caption": "git: show current file at commit",
"command": "gs_show_current_file"
Expand Down
3 changes: 3 additions & 0 deletions common/util/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def refresh_gitsavvy(view, refresh_sidebar=False, refresh_status_bar=True,
if view.settings().get("git_savvy.interface") is not None:
view.run_command("gs_interface_refresh", {"nuke_cursors": interface_reset_cursor})

if view.settings().get("git_savvy.log_graph_view", False):
view.run_command("gs_log_graph_refresh")

if refresh_status_bar:
view.run_command("gs_update_status_bar")

Expand Down
22 changes: 22 additions & 0 deletions core/commands/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ class GsLogCurrentBranchCommand(LogMixin, WindowCommand, GitCommand):
pass


class GsLogRevertCommitCommand(LogMixin, WindowCommand, GitCommand):
def do_action(self, commit_hash, **kwargs):
self.window.run_command("gs_revert_commit", {
"commit_hash": commit_hash
})


class GsRevertCommitCommand(WindowCommand, GitCommand):
def run(self, commit_hash):
sublime.set_timeout_async(lambda: self.run_async(commit_hash=commit_hash), 0)

def run_async(self, commit_hash):
self.git("revert", commit_hash)
util.view.refresh_gitsavvy(self.window.active_view(), refresh_sidebar=True)


class GsLogAllBranchesCommand(LogMixin, WindowCommand, GitCommand):

def log(self, **kwargs):
Expand Down Expand Up @@ -128,6 +144,7 @@ class GsLogActionCommand(PanelActionMixin, WindowCommand, GitCommand):
default_actions = [
["show_commit", "Show commit"],
["checkout_commit", "Checkout commit"],
["revert_commit", "Revert commit"],
["compare_against", "Compare commit against ..."],
["copy_sha", "Copy the full SHA"],
["diff_commit", "Diff commit"],
Expand All @@ -152,6 +169,11 @@ def checkout_commit(self):
self.checkout_ref(self._commit_hash)
util.view.refresh_gitsavvy(self.view, refresh_sidebar=True)

def revert_commit(self):
self.window.run_command("gs_revert_commit", {
"commit_hash": self._commit_hash
})

def compare_against(self):
self.window.run_command("gs_compare_against", {
"base_commit": self._commit_hash,
Expand Down
6 changes: 6 additions & 0 deletions core/commands/log_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def update_actions(self):
if view.settings().get("git_savvy.compare_commit_view.target_commit") == "HEAD":
self.actions.append(["cherry_pick", "Cherry-pick commit"])

if view.settings().get("git_savvy.log_graph_view", False):
self.actions.append(["revert_commit", "Revert commit"])

if view.settings().get("git_savvy.log_graph_view"):
self.actions.extend([
["diff_commit", "Diff commit"],
Expand Down Expand Up @@ -199,6 +202,9 @@ def run(self):
def cherry_pick(self):
self.git("cherry-pick", self._commit_hash)

def revert_commit(self):
self.window.run_command("gs_revert_commit", { "commit_hash": self._commit_hash})

def show_file_at_commit(self):
self.window.run_command(
"gs_show_file_at_commit",
Expand Down

0 comments on commit 81a7624

Please sign in to comment.