# Path: sgit/util.py
# def get_setting(key, default=None):
#     return get_settings().get(key, default)
# 
# 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 GitBranchHelper(object):
# 
#     def get_current_branch(self, repo):
#         branch = self.git_string(['symbolic-ref', '-q', 'HEAD'], cwd=repo)
#         return branch[11:] if branch.startswith('refs/heads/') else branch
# 
#     def get_branches(self, repo, remotes=False):
#         lines = self.git_lines(['branch', '--list', '--no-color', '--remotes' if remotes else None], cwd=repo)
# 
#         branches = []
#         for line in lines:
#             current = line.startswith('*')
#             nameparts = line[2:].split(' -> ')
#             name = nameparts[1] if len(nameparts) == 2 else nameparts[0]
#             branches.append((current, name))
# 
#         return branches
# 
# class GitErrorHelper(object):
# 
#     def format_error_message(self, msg):
#         if msg.startswith('error: '):
#             msg = msg[7:]
#         elif msg.lower().startswith('Note: '):
#             msg = msg[6:]
#         if msg.endswith('Aborting\n'):
#             msg = msg.rstrip()[:-8]
#         return msg


from functools import partial
from sublime_plugin import WindowCommand
from .util import get_setting
from .cmd import GitCmd
from .helpers import GitBranchHelper, GitErrorHelper
import sublime
# coding: utf-8




class GitMergeCommand(WindowCommand, GitCmd, GitBranchHelper, GitErrorHelper):
    """
    Documentation coming soon.
    """

    def run(self):
        repo = self.get_repo()
        if not repo:
            return

        branches = self.get_branches(repo)
        choices = [name for c, name in branches if not c]

        self.window.show_quick_panel(choices, partial(self.on_done, repo, choices), sublime.MONOSPACE_FONT)

    def on_done(self, repo, choices, idx):
        if idx == -1:
            return

        cmd = ['merge', '--no-progress']


# Path: sgit/util.py
# def get_setting(key, default=None):
#     return get_settings().get(key, default)
# 
# 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 GitBranchHelper(object):
# 
#     def get_current_branch(self, repo):
#         branch = self.git_string(['symbolic-ref', '-q', 'HEAD'], cwd=repo)
#         return branch[11:] if branch.startswith('refs/heads/') else branch
# 
#     def get_branches(self, repo, remotes=False):
#         lines = self.git_lines(['branch', '--list', '--no-color', '--remotes' if remotes else None], cwd=repo)
# 
#         branches = []
#         for line in lines:
#             current = line.startswith('*')
#             nameparts = line[2:].split(' -> ')
#             name = nameparts[1] if len(nameparts) == 2 else nameparts[0]
#             branches.append((current, name))
# 
#         return branches
# 
# class GitErrorHelper(object):
# 
#     def format_error_message(self, msg):
#         if msg.startswith('error: '):
#             msg = msg[7:]
#         elif msg.lower().startswith('Note: '):
#             msg = msg[6:]
#         if msg.endswith('Aborting\n'):
#             msg = msg.rstrip()[:-8]
#         return msg


# Path: sgit/merge.py
from functools import partial
from sublime_plugin import WindowCommand
from .util import get_setting
from .cmd import GitCmd
from .helpers import GitBranchHelper, GitErrorHelper
import sublime

# coding: utf-8




class GitMergeCommand(WindowCommand, GitCmd, GitBranchHelper, GitErrorHelper):
    """
    Documentation coming soon.
    """

    def run(self):
        repo = self.get_repo()
        if not repo:
            return

        branches = self.get_branches(repo)
        choices = [name for c, name in branches if not c]

        self.window.show_quick_panel(choices, partial(self.on_done, repo, choices), sublime.MONOSPACE_FONT)

    def on_done(self, repo, choices, idx):
        if idx == -1:
            return

        cmd = ['merge', '--no-progress']


        extra_flags = get_setting('git_merge_flags')