# Path: sgit/util.py
# class StatusSpinner(object):
# 
#     SIZE = 10  # 10 equal signs
#     TIME = 50  # 50 ms delay
# 
#     def __init__(self, thread, msg):
#         self.counter = 0
#         self.direction = 1
#         self.msg = msg
#         self.thread = thread
# 
#     def progress(self):
#         if not self.thread.is_alive():
#             sublime.status_message('')
#             return
# 
#         left, right = self.counter, (self.SIZE - 1 - self.counter)
#         self.counter += self.direction
#         if self.counter in (0, self.SIZE - 1):
#             self.direction *= -1
# 
#         status = "[%s=%s] %s" % (' ' * left, ' ' * right, self.msg)
# 
#         sublime.status_message(status)
#         sublime.set_timeout(self.progress, self.TIME)
# 
#     def start(self):
#         self.thread.start()
#         sublime.set_timeout(self.progress, 0)
# 
# def noop(*args, **kwargs):
#     pass
# 
# Path: sgit/cmd.py
# class GitCmd(GitRepoHelper, Cmd):
#     executable = 'git'
#     bin = ['git']
#     opts = [
#         '--no-pager',
#         '-c', 'color.diff=false',
#         '-c', 'color.status=false',
#         '-c', 'color.branch=false',
#         '-c', 'status.displayCommentPrefix=true',
#         '-c', 'core.commentchar=#',
#     ]
# 
#     def git(self, cmd, *args, **kwargs):
#         return self.cmd(cmd, *args, **kwargs)
# 
#     def git_string(self, cmd, *args, **kwargs):
#         return self._string(cmd, *args, **kwargs)
# 
#     def git_lines(self, cmd, *args, **kwargs):
#         return self._lines(cmd, *args, **kwargs)
# 
#     def git_exit_code(self, cmd, *args, **kwargs):
#         return self._exit_code(cmd, *args, **kwargs)
# 
#     def git_async(self, cmd, *args, **kwargs):
#         return self.cmd_async(cmd, *args, **kwargs)
# 
# Path: sgit/helpers.py
# class GitRemoteHelper(GitBranchHelper):
# 
#     def get_remotes(self, repo):
#         return self.git_lines(['remote', '-v'], cwd=repo)
# 
#     def get_remote_names(self, remotes):
#         names = set()
#         for r in remotes:
#             name, right = r.split('\t', 1)
#             url, action = right.rsplit(' ', 1)
#             names.append(name)
#         return sorted(list(names))
# 
#     def format_quick_remotes(self, remotes):
#         data = {}
#         for r in remotes:
#             name, right = r.split('\t', 1)
#             url, action = right.rsplit(' ', 1)
#             data.setdefault(name, {})[action] = "%s %s" % (url, action)
#         choices = []
#         for remote, urls in list(data.items()):
#             choices.append([remote, urls.get('(fetch)', None), urls.get('(push)', None)])
#         return choices
# 
#     def get_remote_url(self, repo, remote):
#         return self.git_string(['config', 'remote.%s.url' % remote], cwd=repo)
# 
#     def get_branch_upstream(self, repo, branch):
#         return (self.get_branch_remote(repo, branch), self.get_branch_merge(repo, branch))
# 
#     def get_branch_remote(self, repo, branch):
#         return self.git_string(['config', 'branch.%s.remote' % branch], cwd=repo)
# 
#     def get_branch_merge(self, repo, branch):
#         return self.git_string(['config', 'branch.%s.merge' % branch], cwd=repo)
# 
#     def get_remote_branches(self, repo, remote):
#         branches = [b for _, b in self.get_branches(repo, remotes=True)]
#         return [b for b in branches if b.startswith(remote + '/')]
# 
#     def format_quick_branches(self, branches):
#         choices = []
#         for b in branches:
#             branch = b.split('/', 1)[1]
#             choices.append([branch, b])
#         return choices


from functools import partial
from sublime_plugin import WindowCommand
from .util import StatusSpinner, noop
from .cmd import GitCmd
from .helpers import GitRemoteHelper
import sublime
        branch = self.get_current_branch(repo)
        if not branch:
            return sublime.error_message("You really shouldn't push a detached head")

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

        if len(remotes) > 1:
            choices = self.format_quick_remotes(remotes)

            def on_done(idx):
                if idx == -1:
                    return
                branch_remote = choices[idx][0]
                self.on_remote(repo, branch, branch_remote)

            self.window.show_quick_panel(choices, on_done)
        else:
            self.on_remote(repo, branch, remotes[0])

    def on_remote(self, repo, branch, remote):
        def on_done(rbranch):
            rbranch = rbranch.strip()
            if not rbranch:
                return
            self.on_remote_branch(repo, branch, remote, rbranch)


# Path: sgit/util.py
# class StatusSpinner(object):
# 
#     SIZE = 10  # 10 equal signs
#     TIME = 50  # 50 ms delay
# 
#     def __init__(self, thread, msg):
#         self.counter = 0
#         self.direction = 1
#         self.msg = msg
#         self.thread = thread
# 
#     def progress(self):
#         if not self.thread.is_alive():
#             sublime.status_message('')
#             return
# 
#         left, right = self.counter, (self.SIZE - 1 - self.counter)
#         self.counter += self.direction
#         if self.counter in (0, self.SIZE - 1):
#             self.direction *= -1
# 
#         status = "[%s=%s] %s" % (' ' * left, ' ' * right, self.msg)
# 
#         sublime.status_message(status)
#         sublime.set_timeout(self.progress, self.TIME)
# 
#     def start(self):
#         self.thread.start()
#         sublime.set_timeout(self.progress, 0)
# 
# def noop(*args, **kwargs):
#     pass
# 
# Path: sgit/cmd.py
# class GitCmd(GitRepoHelper, Cmd):
#     executable = 'git'
#     bin = ['git']
#     opts = [
#         '--no-pager',
#         '-c', 'color.diff=false',
#         '-c', 'color.status=false',
#         '-c', 'color.branch=false',
#         '-c', 'status.displayCommentPrefix=true',
#         '-c', 'core.commentchar=#',
#     ]
# 
#     def git(self, cmd, *args, **kwargs):
#         return self.cmd(cmd, *args, **kwargs)
# 
#     def git_string(self, cmd, *args, **kwargs):
#         return self._string(cmd, *args, **kwargs)
# 
#     def git_lines(self, cmd, *args, **kwargs):
#         return self._lines(cmd, *args, **kwargs)
# 
#     def git_exit_code(self, cmd, *args, **kwargs):
#         return self._exit_code(cmd, *args, **kwargs)
# 
#     def git_async(self, cmd, *args, **kwargs):
#         return self.cmd_async(cmd, *args, **kwargs)
# 
# Path: sgit/helpers.py
# class GitRemoteHelper(GitBranchHelper):
# 
#     def get_remotes(self, repo):
#         return self.git_lines(['remote', '-v'], cwd=repo)
# 
#     def get_remote_names(self, remotes):
#         names = set()
#         for r in remotes:
#             name, right = r.split('\t', 1)
#             url, action = right.rsplit(' ', 1)
#             names.append(name)
#         return sorted(list(names))
# 
#     def format_quick_remotes(self, remotes):
#         data = {}
#         for r in remotes:
#             name, right = r.split('\t', 1)
#             url, action = right.rsplit(' ', 1)
#             data.setdefault(name, {})[action] = "%s %s" % (url, action)
#         choices = []
#         for remote, urls in list(data.items()):
#             choices.append([remote, urls.get('(fetch)', None), urls.get('(push)', None)])
#         return choices
# 
#     def get_remote_url(self, repo, remote):
#         return self.git_string(['config', 'remote.%s.url' % remote], cwd=repo)
# 
#     def get_branch_upstream(self, repo, branch):
#         return (self.get_branch_remote(repo, branch), self.get_branch_merge(repo, branch))
# 
#     def get_branch_remote(self, repo, branch):
#         return self.git_string(['config', 'branch.%s.remote' % branch], cwd=repo)
# 
#     def get_branch_merge(self, repo, branch):
#         return self.git_string(['config', 'branch.%s.merge' % branch], cwd=repo)
# 
#     def get_remote_branches(self, repo, remote):
#         branches = [b for _, b in self.get_branches(repo, remotes=True)]
#         return [b for b in branches if b.startswith(remote + '/')]
# 
#     def format_quick_branches(self, branches):
#         choices = []
#         for b in branches:
#             branch = b.split('/', 1)[1]
#             choices.append([branch, b])
#         return choices


# Path: sgit/remote.py
from functools import partial
from sublime_plugin import WindowCommand
from .util import StatusSpinner, noop
from .cmd import GitCmd
from .helpers import GitRemoteHelper
import sublime

        branch = self.get_current_branch(repo)
        if not branch:
            return sublime.error_message("You really shouldn't push a detached head")

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

        if len(remotes) > 1:
            choices = self.format_quick_remotes(remotes)

            def on_done(idx):
                if idx == -1:
                    return
                branch_remote = choices[idx][0]
                self.on_remote(repo, branch, branch_remote)

            self.window.show_quick_panel(choices, on_done)
        else:
            self.on_remote(repo, branch, remotes[0])

    def on_remote(self, repo, branch, remote):
        def on_done(rbranch):
            rbranch = rbranch.strip()
            if not rbranch:
                return
            self.on_remote_branch(repo, branch, remote, rbranch)


        self.window.show_input_panel('Remote branch:', branch, on_done, noop, noop)