# 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
            return
        self.view.run_command('save')


class GitQuickCommitCommand(WindowCommand, GitCommitWindowCmd):
    """
    Quickly commit changes with a one-line commit message.

    If there are any staged changes, only those changes will be added. If there
    are no staged changes, any changed files that git know about will be added
    in the commit.

    If the working directory is clean, an error will be shown indicating it.

    After entering the commit message, press enter to commit, or esc to cancel.
    An empty commit message will also result in the commit being cancelled.
    """

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

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

        if not staged and not dirty:
            sublime.error_message(GIT_WORKING_DIR_CLEAN.capitalize())
            return


# 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

            return
        self.view.run_command('save')


class GitQuickCommitCommand(WindowCommand, GitCommitWindowCmd):
    """
    Quickly commit changes with a one-line commit message.

    If there are any staged changes, only those changes will be added. If there
    are no staged changes, any changed files that git know about will be added
    in the commit.

    If the working directory is clean, an error will be shown indicating it.

    After entering the commit message, press enter to commit, or esc to cancel.
    An empty commit message will also result in the commit being cancelled.
    """

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

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

        if not staged and not dirty:
            sublime.error_message(GIT_WORKING_DIR_CLEAN.capitalize())
            return


        self.window.show_input_panel("Commit message:", '', partial(self.on_commit_message, repo), noop, noop)