We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove / deprecate expected_return_code
Since we rely heavily on xargs, this feature doesn't really work as expected.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pre_commit/commands/run.py`
Content:
```
1 from __future__ import print_function
2 from __future__ import unicode_literals
3 
4 import logging
5 import os
6 import sys
7 
8 from pre_commit import color
9 from pre_commit import git
10 from pre_commit.logging_handler import LoggingHandler
11 from pre_commit.output import get_hook_message
12 from pre_commit.output import sys_stdout_write_wrapper
13 from pre_commit.staged_files_only import staged_files_only
14 from pre_commit.util import cmd_output
15 from pre_commit.util import noop_context
16 
17 
18 logger = logging.getLogger('pre_commit')
19 
20 
21 def _get_skips(environ):
22     skips = environ.get('SKIP', '')
23     return set(skip.strip() for skip in skips.split(',') if skip.strip())
24 
25 
26 def _hook_msg_start(hook, verbose):
27     return '{0}{1}'.format(
28         '[{0}] '.format(hook['id']) if verbose else '',
29         hook['name'],
30     )
31 
32 
33 def _print_no_files_skipped(hook, write, args):
34     write(get_hook_message(
35         _hook_msg_start(hook, args.verbose),
36         postfix='(no files to check) ',
37         end_msg='Skipped',
38         end_color=color.TURQUOISE,
39         use_color=args.color,
40     ))
41 
42 
43 def _print_user_skipped(hook, write, args):
44     write(get_hook_message(
45         _hook_msg_start(hook, args.verbose),
46         end_msg='Skipped',
47         end_color=color.YELLOW,
48         use_color=args.color,
49     ))
50 
51 
52 def get_changed_files(new, old):
53     return cmd_output(
54         'git', 'diff', '--name-only', '{0}..{1}'.format(old, new),
55     )[1].splitlines()
56 
57 
58 def get_filenames(args, include_expr, exclude_expr):
59     if args.origin and args.source:
60         getter = git.get_files_matching(
61             lambda: get_changed_files(args.origin, args.source),
62         )
63     elif args.files:
64         getter = git.get_files_matching(lambda: args.files)
65     elif args.all_files:
66         getter = git.get_all_files_matching
67     elif git.is_in_merge_conflict():
68         getter = git.get_conflicted_files_matching
69     else:
70         getter = git.get_staged_files_matching
71     return getter(include_expr, exclude_expr)
72 
73 
74 def _run_single_hook(hook, repo, args, write, skips=frozenset()):
75     filenames = get_filenames(args, hook['files'], hook['exclude'])
76     if hook['id'] in skips:
77         _print_user_skipped(hook, write, args)
78         return 0
79     elif not filenames:
80         _print_no_files_skipped(hook, write, args)
81         return 0
82 
83     # Print the hook and the dots first in case the hook takes hella long to
84     # run.
85     write(get_hook_message(_hook_msg_start(hook, args.verbose), end_len=6))
86     sys.stdout.flush()
87 
88     retcode, stdout, stderr = repo.run_hook(hook, filenames)
89 
90     if retcode != hook['expected_return_value']:
91         retcode = 1
92         print_color = color.RED
93         pass_fail = 'Failed'
94     else:
95         retcode = 0
96         print_color = color.GREEN
97         pass_fail = 'Passed'
98 
99     write(color.format_color(pass_fail, print_color, args.color) + '\n')
100 
101     if (stdout or stderr) and (retcode or args.verbose):
102         write('hookid: {0}\n'.format(hook['id']))
103         write('\n')
104         for output in (stdout, stderr):
105             assert type(output) is bytes, type(output)
106             if output.strip():
107                 write(output.strip() + b'\n')
108         write('\n')
109 
110     return retcode
111 
112 
113 def _run_hooks(repo_hooks, args, write, environ):
114     """Actually run the hooks."""
115     skips = _get_skips(environ)
116     retval = 0
117     for repo, hook in repo_hooks:
118         retval |= _run_single_hook(hook, repo, args, write, skips)
119     return retval
120 
121 
122 def get_repo_hooks(runner):
123     for repo in runner.repositories:
124         for _, hook in repo.hooks:
125             yield (repo, hook)
126 
127 
128 def _has_unmerged_paths(runner):
129     _, stdout, _ = runner.cmd_runner.run(['git', 'ls-files', '--unmerged'])
130     return bool(stdout.strip())
131 
132 
133 def _has_unstaged_config(runner):
134     retcode, _, _ = runner.cmd_runner.run(
135         ('git', 'diff', '--exit-code', runner.config_file_path),
136         retcode=None,
137     )
138     # be explicit, other git errors don't mean it has an unstaged config.
139     return retcode == 1
140 
141 
142 def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
143     no_stash = args.no_stash or args.all_files or bool(args.files)
144     # Set up our logging handler
145     logger.addHandler(LoggingHandler(args.color, write=write))
146     logger.setLevel(logging.INFO)
147 
148     # Check if we have unresolved merge conflict files and fail fast.
149     if _has_unmerged_paths(runner):
150         logger.error('Unmerged files.  Resolve before committing.')
151         return 1
152     if bool(args.source) != bool(args.origin):
153         logger.error('Specify both --origin and --source.')
154         return 1
155     if _has_unstaged_config(runner) and not no_stash:
156         if args.allow_unstaged_config:
157             logger.warn(
158                 'You have an unstaged config file and have specified the '
159                 '--allow-unstaged-config option.\n'
160                 'Note that your config will be stashed before the config is '
161                 'parsed unless --no-stash is specified.',
162             )
163         else:
164             logger.error(
165                 'Your .pre-commit-config.yaml is unstaged.\n'
166                 '`git add .pre-commit-config.yaml` to fix this.\n'
167                 'Run pre-commit with --allow-unstaged-config to silence this.'
168             )
169             return 1
170 
171     if no_stash:
172         ctx = noop_context()
173     else:
174         ctx = staged_files_only(runner.cmd_runner)
175 
176     with ctx:
177         repo_hooks = list(get_repo_hooks(runner))
178 
179         if args.hook:
180             repo_hooks = [
181                 (repo, hook) for repo, hook in repo_hooks
182                 if hook['id'] == args.hook
183             ]
184             if not repo_hooks:
185                 write('No hook with id `{0}`\n'.format(args.hook))
186                 return 1
187 
188         # Filter hooks for stages
189         repo_hooks = [
190             (repo, hook) for repo, hook in repo_hooks
191             if not hook['stages'] or args.hook_stage in hook['stages']
192         ]
193 
194         return _run_hooks(repo_hooks, args, write, environ)
195
```

Path: `pre_commit/clientlib/validate_manifest.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 from pre_commit.clientlib.validate_base import get_run_function
4 from pre_commit.clientlib.validate_base import get_validator
5 from pre_commit.clientlib.validate_base import is_regex_valid
6 from pre_commit.languages.all import all_languages
7 
8 
9 class InvalidManifestError(ValueError):
10     pass
11 
12 
13 MANIFEST_JSON_SCHEMA = {
14     'type': 'array',
15     'minItems': 1,
16     'items': {
17         'type': 'object',
18         'properties': {
19             'id': {'type': 'string'},
20             'name': {'type': 'string'},
21             'description': {'type': 'string', 'default': ''},
22             'entry': {'type': 'string'},
23             'exclude': {'type': 'string', 'default': '^$'},
24             'language': {'type': 'string'},
25             'language_version': {'type': 'string', 'default': 'default'},
26             'files': {'type': 'string'},
27             'expected_return_value': {'type': 'number', 'default': 0},
28             'stages': {
29                 'type': 'array',
30                 'default': [],
31                 'items': {
32                     'type': 'string',
33                 },
34             },
35             'args': {
36                 'type': 'array',
37                 'default': [],
38                 'items': {
39                     'type': 'string',
40                 },
41             },
42         },
43         'required': ['id', 'name', 'entry', 'language', 'files'],
44     },
45 }
46 
47 
48 def validate_languages(hook_config):
49     if hook_config['language'] not in all_languages:
50         raise InvalidManifestError(
51             'Expected language {0} for {1} to be one of {2!r}'.format(
52                 hook_config['id'],
53                 hook_config['language'],
54                 all_languages,
55             )
56         )
57 
58 
59 def validate_files(hook_config):
60     if not is_regex_valid(hook_config['files']):
61         raise InvalidManifestError(
62             'Invalid files regex at {0}: {1}'.format(
63                 hook_config['id'], hook_config['files'],
64             )
65         )
66 
67     if not is_regex_valid(hook_config.get('exclude', '')):
68         raise InvalidManifestError(
69             'Invalid exclude regex at {0}: {1}'.format(
70                 hook_config['id'], hook_config['exclude'],
71             )
72         )
73 
74 
75 def additional_manifest_check(obj):
76     for hook_config in obj:
77         validate_languages(hook_config)
78         validate_files(hook_config)
79 
80 
81 load_manifest = get_validator(
82     MANIFEST_JSON_SCHEMA,
83     InvalidManifestError,
84     additional_manifest_check,
85 )
86 
87 
88 run = get_run_function(
89     'Manifest filenames.',
90     load_manifest,
91     InvalidManifestError,
92 )
93 
94 
95 if __name__ == '__main__':
96     exit(run())
97
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pre_commit/clientlib/validate_manifest.py b/pre_commit/clientlib/validate_manifest.py
--- a/pre_commit/clientlib/validate_manifest.py
+++ b/pre_commit/clientlib/validate_manifest.py
@@ -24,7 +24,6 @@
             'language': {'type': 'string'},
             'language_version': {'type': 'string', 'default': 'default'},
             'files': {'type': 'string'},
-            'expected_return_value': {'type': 'number', 'default': 0},
             'stages': {
                 'type': 'array',
                 'default': [],
diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py
--- a/pre_commit/commands/run.py
+++ b/pre_commit/commands/run.py
@@ -87,7 +87,7 @@
 
     retcode, stdout, stderr = repo.run_hook(hook, filenames)
 
-    if retcode != hook['expected_return_value']:
+    if retcode:
         retcode = 1
         print_color = color.RED
         pass_fail = 'Failed'

{"golden_diff": "diff --git a/pre_commit/clientlib/validate_manifest.py b/pre_commit/clientlib/validate_manifest.py\n--- a/pre_commit/clientlib/validate_manifest.py\n+++ b/pre_commit/clientlib/validate_manifest.py\n@@ -24,7 +24,6 @@\n             'language': {'type': 'string'},\n             'language_version': {'type': 'string', 'default': 'default'},\n             'files': {'type': 'string'},\n-            'expected_return_value': {'type': 'number', 'default': 0},\n             'stages': {\n                 'type': 'array',\n                 'default': [],\ndiff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py\n--- a/pre_commit/commands/run.py\n+++ b/pre_commit/commands/run.py\n@@ -87,7 +87,7 @@\n \n     retcode, stdout, stderr = repo.run_hook(hook, filenames)\n \n-    if retcode != hook['expected_return_value']:\n+    if retcode:\n         retcode = 1\n         print_color = color.RED\n         pass_fail = 'Failed'\n", "issue": "Remove / deprecate expected_return_code\nSince we rely heavily on xargs, this feature doesn't really work as expected.\n\n", "before_files": [{"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\nimport sys\n\nfrom pre_commit import color\nfrom pre_commit import git\nfrom pre_commit.logging_handler import LoggingHandler\nfrom pre_commit.output import get_hook_message\nfrom pre_commit.output import sys_stdout_write_wrapper\nfrom pre_commit.staged_files_only import staged_files_only\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import noop_context\n\n\nlogger = logging.getLogger('pre_commit')\n\n\ndef _get_skips(environ):\n    skips = environ.get('SKIP', '')\n    return set(skip.strip() for skip in skips.split(',') if skip.strip())\n\n\ndef _hook_msg_start(hook, verbose):\n    return '{0}{1}'.format(\n        '[{0}] '.format(hook['id']) if verbose else '',\n        hook['name'],\n    )\n\n\ndef _print_no_files_skipped(hook, write, args):\n    write(get_hook_message(\n        _hook_msg_start(hook, args.verbose),\n        postfix='(no files to check) ',\n        end_msg='Skipped',\n        end_color=color.TURQUOISE,\n        use_color=args.color,\n    ))\n\n\ndef _print_user_skipped(hook, write, args):\n    write(get_hook_message(\n        _hook_msg_start(hook, args.verbose),\n        end_msg='Skipped',\n        end_color=color.YELLOW,\n        use_color=args.color,\n    ))\n\n\ndef get_changed_files(new, old):\n    return cmd_output(\n        'git', 'diff', '--name-only', '{0}..{1}'.format(old, new),\n    )[1].splitlines()\n\n\ndef get_filenames(args, include_expr, exclude_expr):\n    if args.origin and args.source:\n        getter = git.get_files_matching(\n            lambda: get_changed_files(args.origin, args.source),\n        )\n    elif args.files:\n        getter = git.get_files_matching(lambda: args.files)\n    elif args.all_files:\n        getter = git.get_all_files_matching\n    elif git.is_in_merge_conflict():\n        getter = git.get_conflicted_files_matching\n    else:\n        getter = git.get_staged_files_matching\n    return getter(include_expr, exclude_expr)\n\n\ndef _run_single_hook(hook, repo, args, write, skips=frozenset()):\n    filenames = get_filenames(args, hook['files'], hook['exclude'])\n    if hook['id'] in skips:\n        _print_user_skipped(hook, write, args)\n        return 0\n    elif not filenames:\n        _print_no_files_skipped(hook, write, args)\n        return 0\n\n    # Print the hook and the dots first in case the hook takes hella long to\n    # run.\n    write(get_hook_message(_hook_msg_start(hook, args.verbose), end_len=6))\n    sys.stdout.flush()\n\n    retcode, stdout, stderr = repo.run_hook(hook, filenames)\n\n    if retcode != hook['expected_return_value']:\n        retcode = 1\n        print_color = color.RED\n        pass_fail = 'Failed'\n    else:\n        retcode = 0\n        print_color = color.GREEN\n        pass_fail = 'Passed'\n\n    write(color.format_color(pass_fail, print_color, args.color) + '\\n')\n\n    if (stdout or stderr) and (retcode or args.verbose):\n        write('hookid: {0}\\n'.format(hook['id']))\n        write('\\n')\n        for output in (stdout, stderr):\n            assert type(output) is bytes, type(output)\n            if output.strip():\n                write(output.strip() + b'\\n')\n        write('\\n')\n\n    return retcode\n\n\ndef _run_hooks(repo_hooks, args, write, environ):\n    \"\"\"Actually run the hooks.\"\"\"\n    skips = _get_skips(environ)\n    retval = 0\n    for repo, hook in repo_hooks:\n        retval |= _run_single_hook(hook, repo, args, write, skips)\n    return retval\n\n\ndef get_repo_hooks(runner):\n    for repo in runner.repositories:\n        for _, hook in repo.hooks:\n            yield (repo, hook)\n\n\ndef _has_unmerged_paths(runner):\n    _, stdout, _ = runner.cmd_runner.run(['git', 'ls-files', '--unmerged'])\n    return bool(stdout.strip())\n\n\ndef _has_unstaged_config(runner):\n    retcode, _, _ = runner.cmd_runner.run(\n        ('git', 'diff', '--exit-code', runner.config_file_path),\n        retcode=None,\n    )\n    # be explicit, other git errors don't mean it has an unstaged config.\n    return retcode == 1\n\n\ndef run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):\n    no_stash = args.no_stash or args.all_files or bool(args.files)\n    # Set up our logging handler\n    logger.addHandler(LoggingHandler(args.color, write=write))\n    logger.setLevel(logging.INFO)\n\n    # Check if we have unresolved merge conflict files and fail fast.\n    if _has_unmerged_paths(runner):\n        logger.error('Unmerged files.  Resolve before committing.')\n        return 1\n    if bool(args.source) != bool(args.origin):\n        logger.error('Specify both --origin and --source.')\n        return 1\n    if _has_unstaged_config(runner) and not no_stash:\n        if args.allow_unstaged_config:\n            logger.warn(\n                'You have an unstaged config file and have specified the '\n                '--allow-unstaged-config option.\\n'\n                'Note that your config will be stashed before the config is '\n                'parsed unless --no-stash is specified.',\n            )\n        else:\n            logger.error(\n                'Your .pre-commit-config.yaml is unstaged.\\n'\n                '`git add .pre-commit-config.yaml` to fix this.\\n'\n                'Run pre-commit with --allow-unstaged-config to silence this.'\n            )\n            return 1\n\n    if no_stash:\n        ctx = noop_context()\n    else:\n        ctx = staged_files_only(runner.cmd_runner)\n\n    with ctx:\n        repo_hooks = list(get_repo_hooks(runner))\n\n        if args.hook:\n            repo_hooks = [\n                (repo, hook) for repo, hook in repo_hooks\n                if hook['id'] == args.hook\n            ]\n            if not repo_hooks:\n                write('No hook with id `{0}`\\n'.format(args.hook))\n                return 1\n\n        # Filter hooks for stages\n        repo_hooks = [\n            (repo, hook) for repo, hook in repo_hooks\n            if not hook['stages'] or args.hook_stage in hook['stages']\n        ]\n\n        return _run_hooks(repo_hooks, args, write, environ)\n", "path": "pre_commit/commands/run.py"}, {"content": "from __future__ import unicode_literals\n\nfrom pre_commit.clientlib.validate_base import get_run_function\nfrom pre_commit.clientlib.validate_base import get_validator\nfrom pre_commit.clientlib.validate_base import is_regex_valid\nfrom pre_commit.languages.all import all_languages\n\n\nclass InvalidManifestError(ValueError):\n    pass\n\n\nMANIFEST_JSON_SCHEMA = {\n    'type': 'array',\n    'minItems': 1,\n    'items': {\n        'type': 'object',\n        'properties': {\n            'id': {'type': 'string'},\n            'name': {'type': 'string'},\n            'description': {'type': 'string', 'default': ''},\n            'entry': {'type': 'string'},\n            'exclude': {'type': 'string', 'default': '^$'},\n            'language': {'type': 'string'},\n            'language_version': {'type': 'string', 'default': 'default'},\n            'files': {'type': 'string'},\n            'expected_return_value': {'type': 'number', 'default': 0},\n            'stages': {\n                'type': 'array',\n                'default': [],\n                'items': {\n                    'type': 'string',\n                },\n            },\n            'args': {\n                'type': 'array',\n                'default': [],\n                'items': {\n                    'type': 'string',\n                },\n            },\n        },\n        'required': ['id', 'name', 'entry', 'language', 'files'],\n    },\n}\n\n\ndef validate_languages(hook_config):\n    if hook_config['language'] not in all_languages:\n        raise InvalidManifestError(\n            'Expected language {0} for {1} to be one of {2!r}'.format(\n                hook_config['id'],\n                hook_config['language'],\n                all_languages,\n            )\n        )\n\n\ndef validate_files(hook_config):\n    if not is_regex_valid(hook_config['files']):\n        raise InvalidManifestError(\n            'Invalid files regex at {0}: {1}'.format(\n                hook_config['id'], hook_config['files'],\n            )\n        )\n\n    if not is_regex_valid(hook_config.get('exclude', '')):\n        raise InvalidManifestError(\n            'Invalid exclude regex at {0}: {1}'.format(\n                hook_config['id'], hook_config['exclude'],\n            )\n        )\n\n\ndef additional_manifest_check(obj):\n    for hook_config in obj:\n        validate_languages(hook_config)\n        validate_files(hook_config)\n\n\nload_manifest = get_validator(\n    MANIFEST_JSON_SCHEMA,\n    InvalidManifestError,\n    additional_manifest_check,\n)\n\n\nrun = get_run_function(\n    'Manifest filenames.',\n    load_manifest,\n    InvalidManifestError,\n)\n\n\nif __name__ == '__main__':\n    exit(run())\n", "path": "pre_commit/clientlib/validate_manifest.py"}], "after_files": [{"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\nimport sys\n\nfrom pre_commit import color\nfrom pre_commit import git\nfrom pre_commit.logging_handler import LoggingHandler\nfrom pre_commit.output import get_hook_message\nfrom pre_commit.output import sys_stdout_write_wrapper\nfrom pre_commit.staged_files_only import staged_files_only\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import noop_context\n\n\nlogger = logging.getLogger('pre_commit')\n\n\ndef _get_skips(environ):\n    skips = environ.get('SKIP', '')\n    return set(skip.strip() for skip in skips.split(',') if skip.strip())\n\n\ndef _hook_msg_start(hook, verbose):\n    return '{0}{1}'.format(\n        '[{0}] '.format(hook['id']) if verbose else '',\n        hook['name'],\n    )\n\n\ndef _print_no_files_skipped(hook, write, args):\n    write(get_hook_message(\n        _hook_msg_start(hook, args.verbose),\n        postfix='(no files to check) ',\n        end_msg='Skipped',\n        end_color=color.TURQUOISE,\n        use_color=args.color,\n    ))\n\n\ndef _print_user_skipped(hook, write, args):\n    write(get_hook_message(\n        _hook_msg_start(hook, args.verbose),\n        end_msg='Skipped',\n        end_color=color.YELLOW,\n        use_color=args.color,\n    ))\n\n\ndef get_changed_files(new, old):\n    return cmd_output(\n        'git', 'diff', '--name-only', '{0}..{1}'.format(old, new),\n    )[1].splitlines()\n\n\ndef get_filenames(args, include_expr, exclude_expr):\n    if args.origin and args.source:\n        getter = git.get_files_matching(\n            lambda: get_changed_files(args.origin, args.source),\n        )\n    elif args.files:\n        getter = git.get_files_matching(lambda: args.files)\n    elif args.all_files:\n        getter = git.get_all_files_matching\n    elif git.is_in_merge_conflict():\n        getter = git.get_conflicted_files_matching\n    else:\n        getter = git.get_staged_files_matching\n    return getter(include_expr, exclude_expr)\n\n\ndef _run_single_hook(hook, repo, args, write, skips=frozenset()):\n    filenames = get_filenames(args, hook['files'], hook['exclude'])\n    if hook['id'] in skips:\n        _print_user_skipped(hook, write, args)\n        return 0\n    elif not filenames:\n        _print_no_files_skipped(hook, write, args)\n        return 0\n\n    # Print the hook and the dots first in case the hook takes hella long to\n    # run.\n    write(get_hook_message(_hook_msg_start(hook, args.verbose), end_len=6))\n    sys.stdout.flush()\n\n    retcode, stdout, stderr = repo.run_hook(hook, filenames)\n\n    if retcode:\n        retcode = 1\n        print_color = color.RED\n        pass_fail = 'Failed'\n    else:\n        retcode = 0\n        print_color = color.GREEN\n        pass_fail = 'Passed'\n\n    write(color.format_color(pass_fail, print_color, args.color) + '\\n')\n\n    if (stdout or stderr) and (retcode or args.verbose):\n        write('hookid: {0}\\n'.format(hook['id']))\n        write('\\n')\n        for output in (stdout, stderr):\n            assert type(output) is bytes, type(output)\n            if output.strip():\n                write(output.strip() + b'\\n')\n        write('\\n')\n\n    return retcode\n\n\ndef _run_hooks(repo_hooks, args, write, environ):\n    \"\"\"Actually run the hooks.\"\"\"\n    skips = _get_skips(environ)\n    retval = 0\n    for repo, hook in repo_hooks:\n        retval |= _run_single_hook(hook, repo, args, write, skips)\n    return retval\n\n\ndef get_repo_hooks(runner):\n    for repo in runner.repositories:\n        for _, hook in repo.hooks:\n            yield (repo, hook)\n\n\ndef _has_unmerged_paths(runner):\n    _, stdout, _ = runner.cmd_runner.run(['git', 'ls-files', '--unmerged'])\n    return bool(stdout.strip())\n\n\ndef _has_unstaged_config(runner):\n    retcode, _, _ = runner.cmd_runner.run(\n        ('git', 'diff', '--exit-code', runner.config_file_path),\n        retcode=None,\n    )\n    # be explicit, other git errors don't mean it has an unstaged config.\n    return retcode == 1\n\n\ndef run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):\n    no_stash = args.no_stash or args.all_files or bool(args.files)\n    # Set up our logging handler\n    logger.addHandler(LoggingHandler(args.color, write=write))\n    logger.setLevel(logging.INFO)\n\n    # Check if we have unresolved merge conflict files and fail fast.\n    if _has_unmerged_paths(runner):\n        logger.error('Unmerged files.  Resolve before committing.')\n        return 1\n    if bool(args.source) != bool(args.origin):\n        logger.error('Specify both --origin and --source.')\n        return 1\n    if _has_unstaged_config(runner) and not no_stash:\n        if args.allow_unstaged_config:\n            logger.warn(\n                'You have an unstaged config file and have specified the '\n                '--allow-unstaged-config option.\\n'\n                'Note that your config will be stashed before the config is '\n                'parsed unless --no-stash is specified.',\n            )\n        else:\n            logger.error(\n                'Your .pre-commit-config.yaml is unstaged.\\n'\n                '`git add .pre-commit-config.yaml` to fix this.\\n'\n                'Run pre-commit with --allow-unstaged-config to silence this.'\n            )\n            return 1\n\n    if no_stash:\n        ctx = noop_context()\n    else:\n        ctx = staged_files_only(runner.cmd_runner)\n\n    with ctx:\n        repo_hooks = list(get_repo_hooks(runner))\n\n        if args.hook:\n            repo_hooks = [\n                (repo, hook) for repo, hook in repo_hooks\n                if hook['id'] == args.hook\n            ]\n            if not repo_hooks:\n                write('No hook with id `{0}`\\n'.format(args.hook))\n                return 1\n\n        # Filter hooks for stages\n        repo_hooks = [\n            (repo, hook) for repo, hook in repo_hooks\n            if not hook['stages'] or args.hook_stage in hook['stages']\n        ]\n\n        return _run_hooks(repo_hooks, args, write, environ)\n", "path": "pre_commit/commands/run.py"}, {"content": "from __future__ import unicode_literals\n\nfrom pre_commit.clientlib.validate_base import get_run_function\nfrom pre_commit.clientlib.validate_base import get_validator\nfrom pre_commit.clientlib.validate_base import is_regex_valid\nfrom pre_commit.languages.all import all_languages\n\n\nclass InvalidManifestError(ValueError):\n    pass\n\n\nMANIFEST_JSON_SCHEMA = {\n    'type': 'array',\n    'minItems': 1,\n    'items': {\n        'type': 'object',\n        'properties': {\n            'id': {'type': 'string'},\n            'name': {'type': 'string'},\n            'description': {'type': 'string', 'default': ''},\n            'entry': {'type': 'string'},\n            'exclude': {'type': 'string', 'default': '^$'},\n            'language': {'type': 'string'},\n            'language_version': {'type': 'string', 'default': 'default'},\n            'files': {'type': 'string'},\n            'stages': {\n                'type': 'array',\n                'default': [],\n                'items': {\n                    'type': 'string',\n                },\n            },\n            'args': {\n                'type': 'array',\n                'default': [],\n                'items': {\n                    'type': 'string',\n                },\n            },\n        },\n        'required': ['id', 'name', 'entry', 'language', 'files'],\n    },\n}\n\n\ndef validate_languages(hook_config):\n    if hook_config['language'] not in all_languages:\n        raise InvalidManifestError(\n            'Expected language {0} for {1} to be one of {2!r}'.format(\n                hook_config['id'],\n                hook_config['language'],\n                all_languages,\n            )\n        )\n\n\ndef validate_files(hook_config):\n    if not is_regex_valid(hook_config['files']):\n        raise InvalidManifestError(\n            'Invalid files regex at {0}: {1}'.format(\n                hook_config['id'], hook_config['files'],\n            )\n        )\n\n    if not is_regex_valid(hook_config.get('exclude', '')):\n        raise InvalidManifestError(\n            'Invalid exclude regex at {0}: {1}'.format(\n                hook_config['id'], hook_config['exclude'],\n            )\n        )\n\n\ndef additional_manifest_check(obj):\n    for hook_config in obj:\n        validate_languages(hook_config)\n        validate_files(hook_config)\n\n\nload_manifest = get_validator(\n    MANIFEST_JSON_SCHEMA,\n    InvalidManifestError,\n    additional_manifest_check,\n)\n\n\nrun = get_run_function(\n    'Manifest filenames.',\n    load_manifest,\n    InvalidManifestError,\n)\n\n\nif __name__ == '__main__':\n    exit(run())\n", "path": "pre_commit/clientlib/validate_manifest.py"}]}