Skip to content

Commit

Permalink
Feature: pull from remote at Branch dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
randy3k committed Jul 18, 2017
1 parent e51c47a commit b229eec
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,14 @@
{ "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
18 changes: 11 additions & 7 deletions core/commands/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class GsPullCommand(WindowCommand, GitCommand):
Through a series of panels, allow the user to pull from a remote branch.
"""

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

def run_async(self):
Expand Down Expand Up @@ -52,11 +53,12 @@ def on_select_remote(self, remote_index):

self.branches_on_selected_remote = self.list_remote_branches(self.selected_remote)

current_local_branch = self.get_current_branch_name()
if not self.local_branch_name:
self.local_branch_name = self.get_current_branch_name()

try:
pre_selected_idx = self.branches_on_selected_remote.index(
self.selected_remote + "/" + current_local_branch)
self.selected_remote + "/" + self.local_branch_name)
except ValueError:
pre_selected_idx = 0

Expand All @@ -79,14 +81,16 @@ def on_select_branch(self, branch_index):
if branch_index == -1:
return

selected_branch = self.branches_on_selected_remote[branch_index].split("/", 1)[1]
sublime.set_timeout_async(lambda: self.do_pull(self.selected_remote, selected_branch))
selected_remote_branch = self.branches_on_selected_remote[branch_index].split("/", 1)[1]
sublime.set_timeout_async(
lambda: self.do_pull(
self.selected_remote, self.local_branch_name, selected_remote_branch))

def do_pull(self, remote, branch):
def do_pull(self, remote, branch, remote_branch):
"""
Perform `git pull remote branch`.
"""
sublime.status_message("Starting pull...")
self.pull(remote, branch)
self.pull(remote=remote, branch=branch, remote_branch=remote_branch)
sublime.status_message("Pull complete.")
util.view.refresh_gitsavvy(self.window.active_view())
8 changes: 6 additions & 2 deletions core/git_mixins/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ def list_remote_branches(self, remote=None):
# Remove any duplicate branch names.
return [branch for idx, branch in enumerate(branches) if branches.index(branch) == idx]

def pull(self, remote=None, branch=None):
def pull(self, remote=None, branch=None, remote_branch=None):
"""
Pull from the specified remote and branch if provided, otherwise
perform default `git pull`.
"""
self.git("pull", remote, branch)
self.git(
"pull",
remote,
branch if not remote_branch else "{}:{}".format(branch, remote_branch)
)

def push(self, remote=None, branch=None, force=False, remote_branch=None, set_upstream=False):
"""
Expand Down
24 changes: 22 additions & 2 deletions core/interfaces/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ class BranchInterface(ui.Interface, GitCommand):
[c] checkout [p] push selected to remote
[b] create new branch (from HEAD) [P] push all branches to remote
[d] delete [D] delete (force)
[d] delete [h] fetch remote branches
[D] delete (force) [u] pull selected from remote
[R] rename (local) [m] merge selected into active branch
[t] configure tracking [M] fetch and merge into active branch
[o] checkout remote as local [h] fetch remote branches
[o] checkout remote as local
[f] diff against active [l] show branch log
[H] diff history against active [g] show branch log graph
Expand Down Expand Up @@ -420,6 +421,25 @@ def on_select_branch(self, branch_index):
util.view.refresh_gitsavvy(self.view)


class GsBranchesPullSelectedCommand(TextCommand, GitCommand):

"""
Pull selected branch from a remote branch.
"""

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

def run_async(self):
interface = ui.get_interface(self.view.id())
remote_name, branch_name = interface.get_selected_branch()

if not branch_name or remote_name:
return

self.view.window().run_command("gs_pull", {"local_branch_name": branch_name})


class GsBranchesPushSelectedCommand(TextCommand, GitCommand):

"""
Expand Down

0 comments on commit b229eec

Please sign in to comment.