# Path: sgit/util.py
# def find_view_by_settings(window, **kwargs):
#     for view in window.views():
#         s = view.settings()
#         matches = [s.get(k) == v for k, v in list(kwargs.items())]
#         if all(matches):
#             return view
# 
# def noop(*args, **kwargs):
#     pass
# 
# 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 GitStatusHelper(object):
# 
#     def file_in_git(self, repo, filename):
#         return self.git_exit_code(['ls-files', filename, '--error-unmatch'], cwd=repo) == 0
# 
#     def has_changes(self, repo):
#         return self.has_staged_changes(repo) or self.has_unstaged_changes(repo)
# 
#     def has_staged_changes(self, repo):
#         return self.git_exit_code(['diff', '--exit-code', '--quiet', '--cached'], cwd=repo) != 0
# 
#     def has_unstaged_changes(self, repo):
#         return self.git_exit_code(['diff', '--exit-code', '--quiet'], cwd=repo) != 0
# 
#     # def get_porcelain_status(self, repo):
#     #     mode = self.get_untracked_mode()
#     #     cmd = ['status', '--porcelain', ('--untracked-files=%s' % mode) if mode else None]
#     #     return self.git_lines(cmd, cwd=repo)
# 
#     def get_porcelain_status(self, repo):
#         mode = self.get_untracked_mode()
#         cmd = ['status', '-z', ('--untracked-files=%s' % mode) if mode else None]
# 
#         output = self.git_string(cmd, cwd=repo, strip=False)
#         rows = output.split('\x00')
#         lines = []
#         idx = 0
#         while idx < len(rows):
#             row = rows[idx]
#             if row and not row.startswith('#'):
#                 status, filename = row[:2], row[3:]
#                 if status[0] == 'R':
#                     lines.append("%s %s -> %s" % (status, rows[idx + 1], filename))
#                     idx += 1
#                 else:
#                     lines.append("%s %s" % (status, filename))
#             idx += 1
#         return lines
# 
#     def get_files_status(self, repo):
#         untracked, unstaged, staged = [], [], []
#         status = self.get_porcelain_status(repo)
#         for l in status:
#             state, filename = l[:2], l[3:]
#             index, worktree = state
#             if state in ('DD', 'AU', 'UD', 'UA', 'DU', 'AA', 'UU'):
#                 logger.warning("unmerged WTF: %s, %s", state, filename)
#             elif state == '??':
#                 untracked.append(('?', filename))
#             elif state == '!!':
#                 continue
#             else:
#                 if worktree != ' ':
#                     unstaged.append((worktree, filename))
#                 if index != ' ':
#                     staged.append((index, filename))
#         return untracked, unstaged, staged
# 
#     def get_untracked_mode(self):
#         # get untracked files mode
#         setting = get_setting('git_status_untracked_files', 'all')
# 
#         mode = 'all'
#         if setting == 'none':
#             mode = 'no'
#         elif setting == 'auto':
#             mode = None
#         return mode
# 
# Path: sgit/status.py
# GIT_WORKING_DIR_CLEAN = "Nothing to commit (working directory clean)"


from functools import partial
from sublime_plugin import WindowCommand, TextCommand, EventListener
from .util import find_view_by_settings, noop, get_setting
from .cmd import GitCmd
from .helpers import GitStatusHelper
from .status import GIT_WORKING_DIR_CLEAN
import sublime
            status += "\n".join(other)
        else:
            status = stdout

        return GIT_COMMIT_TEMPLATE.format(status=status, old_msg=old_msg)

    def show_commit_panel(self, content):
        panel = self.window.get_output_panel('git-commit')
        panel.run_command('git_panel_write', {'content': content})
        self.window.run_command('show_panel', {'panel': 'output.git-commit'})


class GitCommitCommand(WindowCommand, GitCommitWindowCmd):
    """
    Documentation coming soon.
    """

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

        staged = self.has_staged_changes(repo)
        dirty = self.has_unstaged_changes(repo)

        if not add and not staged:
            return sublime.error_message(GIT_NOTHING_STAGED)
        elif add and (not staged and not dirty):
            return sublime.error_message(GIT_WORKING_DIR_CLEAN)


# Path: sgit/util.py
# def find_view_by_settings(window, **kwargs):
#     for view in window.views():
#         s = view.settings()
#         matches = [s.get(k) == v for k, v in list(kwargs.items())]
#         if all(matches):
#             return view
# 
# def noop(*args, **kwargs):
#     pass
# 
# 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 GitStatusHelper(object):
# 
#     def file_in_git(self, repo, filename):
#         return self.git_exit_code(['ls-files', filename, '--error-unmatch'], cwd=repo) == 0
# 
#     def has_changes(self, repo):
#         return self.has_staged_changes(repo) or self.has_unstaged_changes(repo)
# 
#     def has_staged_changes(self, repo):
#         return self.git_exit_code(['diff', '--exit-code', '--quiet', '--cached'], cwd=repo) != 0
# 
#     def has_unstaged_changes(self, repo):
#         return self.git_exit_code(['diff', '--exit-code', '--quiet'], cwd=repo) != 0
# 
#     # def get_porcelain_status(self, repo):
#     #     mode = self.get_untracked_mode()
#     #     cmd = ['status', '--porcelain', ('--untracked-files=%s' % mode) if mode else None]
#     #     return self.git_lines(cmd, cwd=repo)
# 
#     def get_porcelain_status(self, repo):
#         mode = self.get_untracked_mode()
#         cmd = ['status', '-z', ('--untracked-files=%s' % mode) if mode else None]
# 
#         output = self.git_string(cmd, cwd=repo, strip=False)
#         rows = output.split('\x00')
#         lines = []
#         idx = 0
#         while idx < len(rows):
#             row = rows[idx]
#             if row and not row.startswith('#'):
#                 status, filename = row[:2], row[3:]
#                 if status[0] == 'R':
#                     lines.append("%s %s -> %s" % (status, rows[idx + 1], filename))
#                     idx += 1
#                 else:
#                     lines.append("%s %s" % (status, filename))
#             idx += 1
#         return lines
# 
#     def get_files_status(self, repo):
#         untracked, unstaged, staged = [], [], []
#         status = self.get_porcelain_status(repo)
#         for l in status:
#             state, filename = l[:2], l[3:]
#             index, worktree = state
#             if state in ('DD', 'AU', 'UD', 'UA', 'DU', 'AA', 'UU'):
#                 logger.warning("unmerged WTF: %s, %s", state, filename)
#             elif state == '??':
#                 untracked.append(('?', filename))
#             elif state == '!!':
#                 continue
#             else:
#                 if worktree != ' ':
#                     unstaged.append((worktree, filename))
#                 if index != ' ':
#                     staged.append((index, filename))
#         return untracked, unstaged, staged
# 
#     def get_untracked_mode(self):
#         # get untracked files mode
#         setting = get_setting('git_status_untracked_files', 'all')
# 
#         mode = 'all'
#         if setting == 'none':
#             mode = 'no'
#         elif setting == 'auto':
#             mode = None
#         return mode
# 
# Path: sgit/status.py
# GIT_WORKING_DIR_CLEAN = "Nothing to commit (working directory clean)"


# Path: sgit/commit.py
from functools import partial
from sublime_plugin import WindowCommand, TextCommand, EventListener
from .util import find_view_by_settings, noop, get_setting
from .cmd import GitCmd
from .helpers import GitStatusHelper
from .status import GIT_WORKING_DIR_CLEAN
import sublime

            status += "\n".join(other)
        else:
            status = stdout

        return GIT_COMMIT_TEMPLATE.format(status=status, old_msg=old_msg)

    def show_commit_panel(self, content):
        panel = self.window.get_output_panel('git-commit')
        panel.run_command('git_panel_write', {'content': content})
        self.window.run_command('show_panel', {'panel': 'output.git-commit'})


class GitCommitCommand(WindowCommand, GitCommitWindowCmd):
    """
    Documentation coming soon.
    """

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

        staged = self.has_staged_changes(repo)
        dirty = self.has_unstaged_changes(repo)

        if not add and not staged:
            return sublime.error_message(GIT_NOTHING_STAGED)
        elif add and (not staged and not dirty):
            return sublime.error_message(GIT_WORKING_DIR_CLEAN)


        view = find_view_by_settings(self.window, git_view='commit', git_repo=repo)