Skip to content


Implement basic GitCheckoutRemoteBranchCommand class
Browse files Browse the repository at this point in the history
  • Loading branch information
TJKresch committed Mar 27, 2016
1 parent 49003fa commit ac59838
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

{ "caption": "Git: Checkout", "command": "git_checkout_branch"},
{ "caption": "Git: Checkout New Branch", "command": "git_checkout_new_branch"},
{ "caption": "Git: Checkout Remote Branch", "command": "git_checkout_remote_branch"},
{ "caption": "Git: Checkout Commit", "command": "git_checkout_commit"},
{ "caption": "Git: Checkout Tag", "command": "git_checkout_tag"},
{ "caption": "Git: Checkout Current File", "command": "git_checkout_current_file"},
Expand Down
2 changes: 1 addition & 1 deletion sgit/
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

from .checkout import (GitCheckoutBranchCommand, GitCheckoutCommitCommand,
GitCheckoutNewBranchCommand, GitCheckoutCurrentFileCommand,
GitCheckoutTagCommand, GitCheckoutRemoteBranchCommand)

from .merge import GitMergeCommand

Expand Down
50 changes: 49 additions & 1 deletion sgit/
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

from .util import noop
from .cmd import GitCmd
from .helpers import GitStatusHelper, GitBranchHelper, GitErrorHelper, GitLogHelper
from .helpers import GitStatusHelper, GitBranchHelper, GitErrorHelper, GitLogHelper, GitRemoteHelper
from .helpers import GitTagHelper

GIT_BRANCH_EXISTS_MSG = "The branch %s already exists. Do you want to overwrite it?"

# start for GitCheckoutRemoteBranchCommand
NO_REMOTES = u"No remotes have been configured. Remotes can be added with the Git: Add Remote command. Do you want to add a remote now?"
# end for GitCheckoutRemoteBranchCommand

class GitCheckoutWindowCmd(GitCmd, GitBranchHelper, GitLogHelper, GitErrorHelper):
Expand Down Expand Up @@ -179,6 +182,51 @@ def on_done(self, repo, branch):
self.window.run_command('git_status', {'refresh_only': True})

class GitCheckoutRemoteBranchCommand(WindowCommand, GitCheckoutWindowCmd, GitRemoteHelper):
"""Checkout a remote branch."""
def run(self, repo=None):
repo = self.get_repo()
if not repo:

remotes = self.get_remotes(repo)
if not remotes:
if sublime.ok_cancel_dialog(NO_REMOTES, 'Add Remote'):

choices = self.format_quick_remotes(remotes)
self.window.show_quick_panel(choices, partial(self.remote_panel_done, repo, choices))

def remote_panel_done(self, repo, choices, idx):
if idx != -1:
remote = choices[idx][0]

remote_branches = self.get_remote_branches(repo, remote)
if not remote_branches:
return sublime.error_message("No branches on remote %s" % remote)

branches = self.format_quick_branches(remote_branches)

def on_remote():
self.window.show_quick_panel(branches, partial(self.remote_branch_panel_done, repo, branches))

sublime.set_timeout(on_remote, 50)

def remote_branch_panel_done(self, repo, branches, idx):
if idx != -1:
branch = branches[idx][0]

exit, stdout, stderr = self.git(['checkout', branch], cwd=repo)
if exit == 0:
panel = self.window.get_output_panel('git-checkout')
panel.run_command('git_panel_write', {'content': stderr})
self.window.run_command('show_panel', {'panel': 'output.git-checkout'})
self.window.run_command('git_status', {'refresh_only': True})

class GitCheckoutCurrentFileCommand(TextCommand, GitCmd, GitStatusHelper):
Documentation coming soon.
Expand Down

0 comments on commit ac59838

Please sign in to comment.