Skip to content

Commit

Permalink
Merge pull request #722 from divmain/randy3k/pull
Browse files Browse the repository at this point in the history
Fix: Fetch and Merge at Branch dashboard was not working
  • Loading branch information
asfaltboy committed Jul 27, 2017
2 parents b4ed30c + 5e7a6c8 commit 6dbb2ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 39 deletions.
8 changes: 0 additions & 8 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -966,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
9 changes: 7 additions & 2 deletions core/git_mixins/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ def get_remotes(self):
entries = self.git("remote", "-v").splitlines()
return OrderedDict(re.match("([0-9a-zA-Z_-]+)\t([^ ]+)", entry).groups() for entry in entries)

def fetch(self, remote=None, prune=True):
def fetch(self, remote=None, prune=True, branch=None, remote_branch=None):
"""
If provided, fetch all changes from `remote`. Otherwise, fetch
changes from all remotes.
"""
self.git("fetch", "--prune" if prune else None, remote if remote else "--all")
self.git(
"fetch",
"--prune" if prune else None,
remote if remote else "--all",
branch if not remote_branch else "{}:{}".format(remote_branch, branch)
)

def list_remote_branches(self, remote=None):
"""
Expand Down
47 changes: 18 additions & 29 deletions core/interfaces/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ 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 [u] pull selected from remote
[D] delete (force) [h] fetch remote branches
[R] rename (local) [m] merge selected into active branch
[t] configure tracking [M] fetch and merge into active branch
[d] delete [h] fetch remote branches
[D] delete (force) [m] merge selected into active branch
[R] rename (local) [M] fetch and merge into active branch
[t] configure tracking
[o] checkout remote as local
[f] diff against active [l] show branch log
Expand Down Expand Up @@ -421,25 +421,6 @@ 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 Expand Up @@ -515,16 +496,24 @@ class GsBranchesFetchAndMergeCommand(TextCommand, GitCommand):
Fetch from remote and merge fetched branch into active branch.
"""

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

def run_async(self):
self.interface = ui.get_interface(self.view.id())

branches = self.interface.get_selected_branches(ignore_current_branch=True)
# is remote is not set it is a local branch and can't be fetched
remotes_to_fetch = set(filter(None, (b[0] for b in branches)))
for remote in remotes_to_fetch:
sublime.status_message("Fetching from `{}`...".format(remote))
self.fetch(remote=remote)
sublime.status_message("Fetch from {} complete.".format(remote))

for branch in branches:
if branch[0] is None:
# update local branches which have tracking remote
local_branch = self.get_local_branch(branch[1])
if local_branch.tracking:
remote, remote_branch = local_branch.tracking.split("/", 1)
self.fetch(remote=remote, branch=branch[1], remote_branch=remote_branch)
else:
# fetch remote branches
self.fetch(remote=branch[0], branch=branch[1])

branches_strings = self.interface.create_branches_strs(branches)
self.merge(branches_strings)
Expand Down

0 comments on commit 6dbb2ac

Please sign in to comment.