Skip to content

Commit

Permalink
Merge 5de6410 into c2d42fb
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Jul 28, 2017
2 parents c2d42fb + 5de6410 commit d307fe3
Show file tree
Hide file tree
Showing 20 changed files with 467 additions and 656 deletions.
20 changes: 7 additions & 13 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"args": { "reset": true },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.inline_diff_view", "operator": "equal", "operand": true }
{ "key": "setting.git_savvy.inline_diff_view", "operator": "equal", "operand": true },
{ "key": "setting.git_savvy.inline_diff_view.in_cached_mode", "operator": "equal", "operand": false },
]
},
{
Expand All @@ -35,7 +36,8 @@
"args": { "reset": true },
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.inline_diff_view", "operator": "equal", "operand": true }
{ "key": "setting.git_savvy.inline_diff_view", "operator": "equal", "operand": true },
{ "key": "setting.git_savvy.inline_diff_view.in_cached_mode", "operator": "equal", "operand": false },
]
},
{
Expand Down Expand Up @@ -916,15 +918,15 @@
]
},
{
"keys": ["o"],
"command": "gs_branches_checkout_as_local",
"keys": ["b"],
"command": "gs_branches_create_new",
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.branch_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["b"],
"keys": ["o"],
"command": "gs_branches_create_new",
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
Expand Down Expand Up @@ -964,14 +966,6 @@
{ "key": "setting.git_savvy.branch_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["u"],
"command": "gs_branches_pull_selected",
"context": [
{ "key": "setting.command_mode", "operator": "equal", "operand": false },
{ "key": "setting.git_savvy.branch_view", "operator": "equal", "operand": true }
]
},
{
"keys": ["p"],
"command": "gs_branches_push_selected",
Expand Down
103 changes: 59 additions & 44 deletions core/commands/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

from ..git_command import GitCommand
from ...common import util
from ..ui_mixins.quick_panel import show_branch_panel


NEW_BRANCH_PROMPT = "Branch name:"
NEW_BRANCH_INVALID = "`{}` is a invalid branch name.\nRead more on $(man git-check-ref-format)"


class GsCheckoutBranchCommand(WindowCommand, GitCommand):
Expand All @@ -16,32 +18,24 @@ class GsCheckoutBranchCommand(WindowCommand, GitCommand):
user selected.
"""

def run(self):
sublime.set_timeout_async(self.run_async, 0)

def run_async(self):
stdout = self.git("branch", "--no-color")
branch_entries = (branch.strip() for branch in stdout.split("\n") if branch)
def run(self, branch=None):
sublime.set_timeout_async(lambda: self.run_async(branch), 0)

# The line with the active branch will begin with an asterisk.
self.local_inactive_branches = [branch for branch in branch_entries if not branch[0] == "*"]

if not self.local_inactive_branches:
self.window.show_quick_panel(["There are no branches available."], None)
def run_async(self, branch):
if branch:
self.on_branch_selection(branch)
else:
self.window.show_quick_panel(
self.local_inactive_branches,
self.on_selection,
flags=sublime.MONOSPACE_FONT
)

def on_selection(self, branch_name_index):
if branch_name_index == -1:
show_branch_panel(
self.on_branch_selection,
local_branches_only=True,
ignore_current_branch=True)

def on_branch_selection(self, branch):
if not branch:
return

branch_name = self.local_inactive_branches[branch_name_index]
self.git("checkout", branch_name)
sublime.status_message("Checked out `{}` branch.".format(branch_name))
self.git("checkout", branch)
sublime.status_message("Checked out `{}` branch.".format(branch))
util.view.refresh_gitsavvy(self.window.active_view(), refresh_sidebar=True)


Expand All @@ -51,21 +45,25 @@ class GsCheckoutNewBranchCommand(WindowCommand, GitCommand):
Prompt the user for a new branch name, create it, and check it out.
"""

def run(self):
sublime.set_timeout_async(self.run_async)
def run(self, base_branch=None):
sublime.set_timeout_async(lambda: self.run_async(base_branch))

def run_async(self, name=""):
self.window.show_input_panel(NEW_BRANCH_PROMPT, name, self.on_done, None, None)
def run_async(self, base_branch=None):
self.base_branch = base_branch
self.window.show_input_panel(NEW_BRANCH_PROMPT, "", self.on_done, None, None)

def on_done(self, branch_name):
pattern = r"^(?!\.|.*\.\..*|.*@.*|\/)[a-zA-Z0-9\-\_\/\.\u263a-\U0001f645]+(?<!\.lock)(?<!\/)(?<!\.)$"
match = re.match(pattern, branch_name)
if not match:
sublime.error_message("`{}` is a invalid branch name.\nRead more on $(man git-check-ref-format)".format(branch_name))
sublime.error_message(NEW_BRANCH_INVALID.format(branch_name))
sublime.set_timeout_async(self.run_async(branch_name))
return None

self.git("checkout", "-b", branch_name)
self.git(
"checkout", "-b",
branch_name,
self.base_branch if self.base_branch else None)
sublime.status_message("Created and checked out `{}` branch.".format(branch_name))
util.view.refresh_gitsavvy(self.window.active_view())

Expand All @@ -78,25 +76,42 @@ class GsCheckoutRemoteBranchCommand(WindowCommand, GitCommand):
selected branch.
"""

def run(self):
sublime.set_timeout_async(self.run_async)

def run_async(self):
self.remote_branches = self.list_remote_branches()
self.window.show_quick_panel(
self.remote_branches,
self.on_selection,
flags=sublime.MONOSPACE_FONT
)

def on_selection(self, remote_branch_index):
if remote_branch_index == -1:
def run(self, remote_branch=None):
sublime.set_timeout_async(lambda: self.run_async(remote_branch))

def run_async(self, remote_branch):
if remote_branch:
self.on_branch_selection(remote_branch)
else:
show_branch_panel(
self.on_branch_selection,
remote_branches_only=True)

def on_branch_selection(self, remote_branch):
if not remote_branch:
return

remote_branch = self.remote_branches[remote_branch_index]
self.remote_branch = remote_branch
local_name = remote_branch.split("/", 1)[1]
self.git("checkout", "-b", local_name, "--track", remote_branch)
sublime.status_message("Checked out `{}` as local branch `{}`.".format(remote_branch, local_name))
v = self.window.show_input_panel(
NEW_BRANCH_PROMPT,
local_name,
self.on_enter_local_name,
None,
None)
v.run_command("select_all")

def on_enter_local_name(self, branch_name):
pattern = r"^(?!\.|.*\.\..*|.*@.*|\/)[a-zA-Z0-9\-\_\/\.\u263a-\U0001f645]+(?<!\.lock)(?<!\/)(?<!\.)$"
match = re.match(pattern, branch_name)
if not match:
sublime.error_message(NEW_BRANCH_INVALID.format(branch_name))
sublime.set_timeout_async(self.on_branch_selection(self.remote_branch))
return None

self.git("checkout", "-b", branch_name, "--track", self.remote_branch)
sublime.status_message(
"Checked out `{}` as local branch `{}`.".format(self.remote_branch, branch_name))
util.view.refresh_gitsavvy(self.window.active_view(), refresh_sidebar=True)


Expand Down
33 changes: 10 additions & 23 deletions core/commands/commit_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ...common import util
from ..git_command import GitCommand
from ..ui_mixins.quick_panel import PanelActionMixin
from ..ui_mixins.quick_panel import PanelActionMixin, show_branch_panel


COMMIT_NODE_CHAR = "●"
Expand Down Expand Up @@ -146,35 +146,22 @@ def run(self, base_commit=None, target_commit=None, file_path=None):
self._target_commit = target_commit
sublime.set_timeout_async(self.run_async)

def run_async(self):
self.all_branches = [b.name_with_remote for b in self.get_branches()]
def run_async(self, **kwargs):
show_branch_panel(self.on_branch_selection)

if hasattr(self, '_selected_branch') and self._selected_branch in self.all_branches:
pre_selected_index = self.all_branches.index(self._selected_branch)
def on_branch_selection(self, branch):
if branch:
self.window.run_command("gs_compare_commit", {
"file_path": self._file_path,
"base_commit": self._base_commit if self._base_commit else branch,
"target_commit": self._target_commit if self._target_commit else branch
})
else:
pre_selected_index = self.all_branches.index(self.get_current_branch_name())

self.window.show_quick_panel(
self.all_branches,
self.on_branch_selection,
flags=sublime.MONOSPACE_FONT,
selected_index=pre_selected_index,
)

def on_branch_selection(self, index):
if index == -1:
self.window.run_command("gs_compare_against", {
"base_commit": self._base_commit,
"target_commit": self._target_commit,
"file_path": self._file_path
})
return
selected_branch = self.all_branches[index]
self.window.run_command("gs_compare_commit", {
"file_path": self._file_path,
"base_commit": self._base_commit if self._base_commit else selected_branch,
"target_commit": self._target_commit if self._target_commit else selected_branch
})


class GsCompareAgainstCommand(PanelActionMixin, WindowCommand, GitCommand):
Expand Down
39 changes: 10 additions & 29 deletions core/commands/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

from ..git_command import GitCommand
from ...common import util


ALL_REMOTES = "All remotes."
from ..ui_mixins.quick_panel import show_remote_panel


class GsFetchCommand(WindowCommand, GitCommand):
Expand All @@ -19,39 +17,22 @@ def run(self, remote=None):
if remote:
return self.do_fetch(remote)

self.remotes = list(self.get_remotes().keys())
show_remote_panel(self.on_remote_selection, show_all=True)

if not self.remotes:
self.window.show_quick_panel(["There are no remotes available."], None)
else:
if len(self.remotes) > 1:
self.remotes.append(ALL_REMOTES)

pre_selected_idx = (self.remotes.index(self.last_remote_used)
if self.last_remote_used in self.remotes
else 0)

self.window.show_quick_panel(
self.remotes,
self.on_selection,
flags=sublime.MONOSPACE_FONT,
selected_index=pre_selected_idx
)

def on_selection(self, remotes_index):
# User cancelled.
if remotes_index == -1:
def on_remote_selection(self, remote):
if not remote:
return
remote = self.remotes[remotes_index]

if remote == ALL_REMOTES:
if remote is True:
sublime.set_timeout_async(lambda: self.do_fetch())
else:
self.last_remote_used = remote
sublime.set_timeout_async(lambda: self.do_fetch(remote))

def do_fetch(self, remote=None):
sublime.status_message("Starting fetch...")
if remote is None:
sublime.status_message("Starting fetch all remotes...")
else:
sublime.status_message("Starting fetch {}...".format(remote))

self.fetch(remote)
sublime.status_message("Fetch complete.")
util.view.refresh_gitsavvy(self.window.active_view())
6 changes: 3 additions & 3 deletions core/commands/inline_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_async(self, settings=None, cached=False):
file_ext = util.file.get_file_extension(os.path.basename(settings["git_savvy.file_path"]))
self.augment_color_scheme(diff_view, file_ext)

diff_view.settings().set("git_savvy.inline_diff.cached", cached)
diff_view.settings().set("git_savvy.inline_diff_view.in_cached_mode", cached)
for k, v in settings.items():
diff_view.settings().set(k, v)

Expand Down Expand Up @@ -142,7 +142,7 @@ class GsInlineDiffRefreshCommand(TextCommand, GitCommand):

def run(self, edit):
file_path = self.file_path
in_cached_mode = self.view.settings().get("git_savvy.inline_diff.cached")
in_cached_mode = self.view.settings().get("git_savvy.inline_diff_view.in_cached_mode")
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
ignore_eol_arg = (
"--ignore-space-at-eol"
Expand Down Expand Up @@ -397,7 +397,7 @@ def run(self, edit, **kwargs):
sublime.set_timeout_async(lambda: self.run_async(**kwargs), 0)

def run_async(self, reset=False):
in_cached_mode = self.view.settings().get("git_savvy.inline_diff.cached")
in_cached_mode = self.view.settings().get("git_savvy.inline_diff_view.in_cached_mode")
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
ignore_ws = (
"--ignore-whitespace"
Expand Down
Loading

0 comments on commit d307fe3

Please sign in to comment.