We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
UnicodeEncodeError when writing to stdout in python2.6 
```
$ pre-commit run fixmyjs
fixmyjs............................................................................................................................................................................................Failed
hookid: fixmyjs

Traceback (most recent call last):
  File "virtualenv_run/bin/pre-commit", line 14, in <module>
    sys.exit(main())
  File "virtualenv_run/lib/python2.6/site-packages/pre_commit/util.py", line 41, in wrapper
    return func(argv)
  File "virtualenv_run/lib/python2.6/site-packages/pre_commit/main.py", line 99, in main
    return run(runner, args)
  File "virtualenv_run/lib/python2.6/site-packages/pre_commit/commands/run.py", line 144, in run
    return _run_hook(runner, args, write=write)
  File "virtualenv_run/lib/python2.6/site-packages/pre_commit/commands/run.py", line 116, in _run_hook
    return _run_single_hook(runner, repo, hook_id, args, write=write)
  File "virtualenv_run/lib/python2.6/site-packages/pre_commit/commands/run.py", line 91, in _run_single_hook
    write(output.strip() + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2713' in position 0: ordinal not in range(128)
```


--- 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/output.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 import subprocess
4 
5 from pre_commit import color
6 
7 
8 # TODO: smell: import side-effects
9 COLS = int(
10     subprocess.Popen(
11         ['tput', 'cols'], stdout=subprocess.PIPE
12     ).communicate()[0] or
13     # Default in the case of no terminal
14     80
15 )
16 
17 
18 def get_hook_message(
19         start,
20         postfix='',
21         end_msg=None,
22         end_len=0,
23         end_color=None,
24         use_color=None,
25         cols=COLS,
26 ):
27     """Prints a message for running a hook.
28 
29     This currently supports three approaches:
30 
31     # Print `start` followed by dots, leaving 6 characters at the end
32     >>> print_hook_message('start', end_len=6)
33     start...............................................................
34 
35     # Print `start` followed by dots with the end message colored if coloring
36     # is specified and a newline afterwards
37     >>> print_hook_message(
38         'start',
39         end_msg='end',
40         end_color=color.RED,
41         use_color=True,
42     )
43     start...................................................................end
44 
45     # Print `start` followed by dots, followed by the `postfix` message
46     # uncolored, followed by the `end_msg` colored if specified and a newline
47     # afterwards
48     >>> print_hook_message(
49         'start',
50         postfix='postfix ',
51         end_msg='end',
52         end_color=color.RED,
53         use_color=True,
54     )
55     start...........................................................postfix end
56     """
57     if bool(end_msg) == bool(end_len):
58         raise ValueError('Expected one of (`end_msg`, `end_len`)')
59     if end_msg is not None and (end_color is None or use_color is None):
60         raise ValueError(
61             '`end_color` and `use_color` are required with `end_msg`'
62         )
63 
64     if end_len:
65         return start + '.' * (cols - len(start) - end_len - 1)
66     else:
67         return '{0}{1}{2}{3}\n'.format(
68             start,
69             '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),
70             postfix,
71             color.format_color(end_msg, end_color, use_color),
72         )
73
```

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 git
9 from pre_commit import color
10 from pre_commit.logging_handler import LoggingHandler
11 from pre_commit.output import get_hook_message
12 from pre_commit.staged_files_only import staged_files_only
13 from pre_commit.util import noop_context
14 
15 
16 logger = logging.getLogger('pre_commit')
17 
18 
19 def _get_skips(environ):
20     skips = environ.get('SKIP', '')
21     return set(skip.strip() for skip in skips.split(',') if skip.strip())
22 
23 
24 def _hook_msg_start(hook, verbose):
25     return '{0}{1}'.format(
26         '[{0}] '.format(hook['id']) if verbose else '',
27         hook['name'],
28     )
29 
30 
31 def _print_no_files_skipped(hook, write, args):
32     write(get_hook_message(
33         _hook_msg_start(hook, args.verbose),
34         postfix='(no files to check) ',
35         end_msg='Skipped',
36         end_color=color.TURQUOISE,
37         use_color=args.color,
38     ))
39 
40 
41 def _print_user_skipped(hook, write, args):
42     write(get_hook_message(
43         _hook_msg_start(hook, args.verbose),
44         end_msg='Skipped',
45         end_color=color.YELLOW,
46         use_color=args.color,
47     ))
48 
49 
50 def _run_single_hook(runner, repository, hook, args, write, skips=set()):
51     if args.all_files:
52         get_filenames = git.get_all_files_matching
53     elif git.is_in_merge_conflict():
54         get_filenames = git.get_conflicted_files_matching
55     else:
56         get_filenames = git.get_staged_files_matching
57 
58     filenames = get_filenames(hook['files'], hook['exclude'])
59     if hook['id'] in skips:
60         _print_user_skipped(hook, write, args)
61         return 0
62     elif not filenames:
63         _print_no_files_skipped(hook, write, args)
64         return 0
65 
66     # Print the hook and the dots first in case the hook takes hella long to
67     # run.
68     write(get_hook_message(_hook_msg_start(hook, args.verbose), end_len=6))
69     sys.stdout.flush()
70 
71     retcode, stdout, stderr = repository.run_hook(hook, filenames)
72 
73     if retcode != hook['expected_return_value']:
74         retcode = 1
75         print_color = color.RED
76         pass_fail = 'Failed'
77     else:
78         retcode = 0
79         print_color = color.GREEN
80         pass_fail = 'Passed'
81 
82     write(color.format_color(pass_fail, print_color, args.color) + '\n')
83 
84     if (stdout or stderr) and (retcode or args.verbose):
85         write('hookid: {0}\n'.format(hook['id']))
86         write('\n')
87         for output in (stdout, stderr):
88             if output.strip():
89                 write(output.strip() + '\n')
90         write('\n')
91 
92     return retcode
93 
94 
95 def _run_hooks(runner, args, write, environ):
96     """Actually run the hooks."""
97     retval = 0
98 
99     skips = _get_skips(environ)
100 
101     for repo in runner.repositories:
102         for _, hook in repo.hooks:
103             retval |= _run_single_hook(
104                 runner, repo, hook, args, write, skips=skips,
105             )
106 
107     return retval
108 
109 
110 def _run_hook(runner, args, write):
111     hook_id = args.hook
112     for repo in runner.repositories:
113         for hook_id_in_repo, hook in repo.hooks:
114             if hook_id == hook_id_in_repo:
115                 return _run_single_hook(
116                     runner, repo, hook, args, write=write,
117                 )
118     else:
119         write('No hook with id `{0}`\n'.format(hook_id))
120         return 1
121 
122 
123 def _has_unmerged_paths(runner):
124     _, stdout, _ = runner.cmd_runner.run(['git', 'ls-files', '--unmerged'])
125     return bool(stdout.strip())
126 
127 
128 def run(runner, args, write=sys.stdout.write, environ=os.environ):
129     # Set up our logging handler
130     logger.addHandler(LoggingHandler(args.color, write=write))
131     logger.setLevel(logging.INFO)
132 
133     # Check if we have unresolved merge conflict files and fail fast.
134     if _has_unmerged_paths(runner):
135         logger.error('Unmerged files.  Resolve before committing.')
136         return 1
137 
138     if args.no_stash or args.all_files:
139         ctx = noop_context()
140     else:
141         ctx = staged_files_only(runner.cmd_runner)
142 
143     with ctx:
144         if args.hook:
145             return _run_hook(runner, args, write=write)
146         else:
147             return _run_hooks(runner, args, write=write, environ=environ)
148
```
--- 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/commands/run.py b/pre_commit/commands/run.py
--- a/pre_commit/commands/run.py
+++ b/pre_commit/commands/run.py
@@ -9,6 +9,7 @@
 from pre_commit import color
 from pre_commit.logging_handler import LoggingHandler
 from pre_commit.output import get_hook_message
+from pre_commit.output import sys_stdout_write_wrapper
 from pre_commit.staged_files_only import staged_files_only
 from pre_commit.util import noop_context
 
@@ -125,7 +126,7 @@
     return bool(stdout.strip())
 
 
-def run(runner, args, write=sys.stdout.write, environ=os.environ):
+def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
     # Set up our logging handler
     logger.addHandler(LoggingHandler(args.color, write=write))
     logger.setLevel(logging.INFO)
diff --git a/pre_commit/output.py b/pre_commit/output.py
--- a/pre_commit/output.py
+++ b/pre_commit/output.py
@@ -1,8 +1,10 @@
 from __future__ import unicode_literals
 
 import subprocess
+import sys
 
 from pre_commit import color
+from pre_commit import five
 
 
 # TODO: smell: import side-effects
@@ -70,3 +72,14 @@
             postfix,
             color.format_color(end_msg, end_color, use_color),
         )
+
+
+def sys_stdout_write_wrapper(s, stream=sys.stdout):
+    """Python 2.6 chokes on unicode being passed to sys.stdout.write.
+
+    This is an adapter because PY2 is ok with bytes and PY3 requires text.
+    """
+    assert type(s) is five.text
+    if five.PY2:  # pragma: no cover (PY2)
+        s = s.encode('UTF-8')
+    stream.write(s)

{"golden_diff": "diff --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@@ -9,6 +9,7 @@\n from pre_commit import color\n from pre_commit.logging_handler import LoggingHandler\n from pre_commit.output import get_hook_message\n+from pre_commit.output import sys_stdout_write_wrapper\n from pre_commit.staged_files_only import staged_files_only\n from pre_commit.util import noop_context\n \n@@ -125,7 +126,7 @@\n     return bool(stdout.strip())\n \n \n-def run(runner, args, write=sys.stdout.write, environ=os.environ):\n+def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):\n     # Set up our logging handler\n     logger.addHandler(LoggingHandler(args.color, write=write))\n     logger.setLevel(logging.INFO)\ndiff --git a/pre_commit/output.py b/pre_commit/output.py\n--- a/pre_commit/output.py\n+++ b/pre_commit/output.py\n@@ -1,8 +1,10 @@\n from __future__ import unicode_literals\n \n import subprocess\n+import sys\n \n from pre_commit import color\n+from pre_commit import five\n \n \n # TODO: smell: import side-effects\n@@ -70,3 +72,14 @@\n             postfix,\n             color.format_color(end_msg, end_color, use_color),\n         )\n+\n+\n+def sys_stdout_write_wrapper(s, stream=sys.stdout):\n+    \"\"\"Python 2.6 chokes on unicode being passed to sys.stdout.write.\n+\n+    This is an adapter because PY2 is ok with bytes and PY3 requires text.\n+    \"\"\"\n+    assert type(s) is five.text\n+    if five.PY2:  # pragma: no cover (PY2)\n+        s = s.encode('UTF-8')\n+    stream.write(s)\n", "issue": "UnicodeEncodeError when writing to stdout in python2.6 \n```\n$ pre-commit run fixmyjs\nfixmyjs............................................................................................................................................................................................Failed\nhookid: fixmyjs\n\nTraceback (most recent call last):\n  File \"virtualenv_run/bin/pre-commit\", line 14, in <module>\n    sys.exit(main())\n  File \"virtualenv_run/lib/python2.6/site-packages/pre_commit/util.py\", line 41, in wrapper\n    return func(argv)\n  File \"virtualenv_run/lib/python2.6/site-packages/pre_commit/main.py\", line 99, in main\n    return run(runner, args)\n  File \"virtualenv_run/lib/python2.6/site-packages/pre_commit/commands/run.py\", line 144, in run\n    return _run_hook(runner, args, write=write)\n  File \"virtualenv_run/lib/python2.6/site-packages/pre_commit/commands/run.py\", line 116, in _run_hook\n    return _run_single_hook(runner, repo, hook_id, args, write=write)\n  File \"virtualenv_run/lib/python2.6/site-packages/pre_commit/commands/run.py\", line 91, in _run_single_hook\n    write(output.strip() + '\\n')\nUnicodeEncodeError: 'ascii' codec can't encode character u'\\u2713' in position 0: ordinal not in range(128)\n```\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport subprocess\n\nfrom pre_commit import color\n\n\n# TODO: smell: import side-effects\nCOLS = int(\n    subprocess.Popen(\n        ['tput', 'cols'], stdout=subprocess.PIPE\n    ).communicate()[0] or\n    # Default in the case of no terminal\n    80\n)\n\n\ndef get_hook_message(\n        start,\n        postfix='',\n        end_msg=None,\n        end_len=0,\n        end_color=None,\n        use_color=None,\n        cols=COLS,\n):\n    \"\"\"Prints a message for running a hook.\n\n    This currently supports three approaches:\n\n    # Print `start` followed by dots, leaving 6 characters at the end\n    >>> print_hook_message('start', end_len=6)\n    start...............................................................\n\n    # Print `start` followed by dots with the end message colored if coloring\n    # is specified and a newline afterwards\n    >>> print_hook_message(\n        'start',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...................................................................end\n\n    # Print `start` followed by dots, followed by the `postfix` message\n    # uncolored, followed by the `end_msg` colored if specified and a newline\n    # afterwards\n    >>> print_hook_message(\n        'start',\n        postfix='postfix ',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...........................................................postfix end\n    \"\"\"\n    if bool(end_msg) == bool(end_len):\n        raise ValueError('Expected one of (`end_msg`, `end_len`)')\n    if end_msg is not None and (end_color is None or use_color is None):\n        raise ValueError(\n            '`end_color` and `use_color` are required with `end_msg`'\n        )\n\n    if end_len:\n        return start + '.' * (cols - len(start) - end_len - 1)\n    else:\n        return '{0}{1}{2}{3}\\n'.format(\n            start,\n            '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),\n            postfix,\n            color.format_color(end_msg, end_color, use_color),\n        )\n", "path": "pre_commit/output.py"}, {"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\nimport sys\n\nfrom pre_commit import git\nfrom pre_commit import color\nfrom pre_commit.logging_handler import LoggingHandler\nfrom pre_commit.output import get_hook_message\nfrom pre_commit.staged_files_only import staged_files_only\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 _run_single_hook(runner, repository, hook, args, write, skips=set()):\n    if args.all_files:\n        get_filenames = git.get_all_files_matching\n    elif git.is_in_merge_conflict():\n        get_filenames = git.get_conflicted_files_matching\n    else:\n        get_filenames = git.get_staged_files_matching\n\n    filenames = get_filenames(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 = repository.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            if output.strip():\n                write(output.strip() + '\\n')\n        write('\\n')\n\n    return retcode\n\n\ndef _run_hooks(runner, args, write, environ):\n    \"\"\"Actually run the hooks.\"\"\"\n    retval = 0\n\n    skips = _get_skips(environ)\n\n    for repo in runner.repositories:\n        for _, hook in repo.hooks:\n            retval |= _run_single_hook(\n                runner, repo, hook, args, write, skips=skips,\n            )\n\n    return retval\n\n\ndef _run_hook(runner, args, write):\n    hook_id = args.hook\n    for repo in runner.repositories:\n        for hook_id_in_repo, hook in repo.hooks:\n            if hook_id == hook_id_in_repo:\n                return _run_single_hook(\n                    runner, repo, hook, args, write=write,\n                )\n    else:\n        write('No hook with id `{0}`\\n'.format(hook_id))\n        return 1\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 run(runner, args, write=sys.stdout.write, environ=os.environ):\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\n    if args.no_stash or args.all_files:\n        ctx = noop_context()\n    else:\n        ctx = staged_files_only(runner.cmd_runner)\n\n    with ctx:\n        if args.hook:\n            return _run_hook(runner, args, write=write)\n        else:\n            return _run_hooks(runner, args, write=write, environ=environ)\n", "path": "pre_commit/commands/run.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport subprocess\nimport sys\n\nfrom pre_commit import color\nfrom pre_commit import five\n\n\n# TODO: smell: import side-effects\nCOLS = int(\n    subprocess.Popen(\n        ['tput', 'cols'], stdout=subprocess.PIPE\n    ).communicate()[0] or\n    # Default in the case of no terminal\n    80\n)\n\n\ndef get_hook_message(\n        start,\n        postfix='',\n        end_msg=None,\n        end_len=0,\n        end_color=None,\n        use_color=None,\n        cols=COLS,\n):\n    \"\"\"Prints a message for running a hook.\n\n    This currently supports three approaches:\n\n    # Print `start` followed by dots, leaving 6 characters at the end\n    >>> print_hook_message('start', end_len=6)\n    start...............................................................\n\n    # Print `start` followed by dots with the end message colored if coloring\n    # is specified and a newline afterwards\n    >>> print_hook_message(\n        'start',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...................................................................end\n\n    # Print `start` followed by dots, followed by the `postfix` message\n    # uncolored, followed by the `end_msg` colored if specified and a newline\n    # afterwards\n    >>> print_hook_message(\n        'start',\n        postfix='postfix ',\n        end_msg='end',\n        end_color=color.RED,\n        use_color=True,\n    )\n    start...........................................................postfix end\n    \"\"\"\n    if bool(end_msg) == bool(end_len):\n        raise ValueError('Expected one of (`end_msg`, `end_len`)')\n    if end_msg is not None and (end_color is None or use_color is None):\n        raise ValueError(\n            '`end_color` and `use_color` are required with `end_msg`'\n        )\n\n    if end_len:\n        return start + '.' * (cols - len(start) - end_len - 1)\n    else:\n        return '{0}{1}{2}{3}\\n'.format(\n            start,\n            '.' * (cols - len(start) - len(postfix) - len(end_msg) - 1),\n            postfix,\n            color.format_color(end_msg, end_color, use_color),\n        )\n\n\ndef sys_stdout_write_wrapper(s, stream=sys.stdout):\n    \"\"\"Python 2.6 chokes on unicode being passed to sys.stdout.write.\n\n    This is an adapter because PY2 is ok with bytes and PY3 requires text.\n    \"\"\"\n    assert type(s) is five.text\n    if five.PY2:  # pragma: no cover (PY2)\n        s = s.encode('UTF-8')\n    stream.write(s)\n", "path": "pre_commit/output.py"}, {"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\nimport sys\n\nfrom pre_commit import git\nfrom pre_commit import color\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 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 _run_single_hook(runner, repository, hook, args, write, skips=set()):\n    if args.all_files:\n        get_filenames = git.get_all_files_matching\n    elif git.is_in_merge_conflict():\n        get_filenames = git.get_conflicted_files_matching\n    else:\n        get_filenames = git.get_staged_files_matching\n\n    filenames = get_filenames(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 = repository.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            if output.strip():\n                write(output.strip() + '\\n')\n        write('\\n')\n\n    return retcode\n\n\ndef _run_hooks(runner, args, write, environ):\n    \"\"\"Actually run the hooks.\"\"\"\n    retval = 0\n\n    skips = _get_skips(environ)\n\n    for repo in runner.repositories:\n        for _, hook in repo.hooks:\n            retval |= _run_single_hook(\n                runner, repo, hook, args, write, skips=skips,\n            )\n\n    return retval\n\n\ndef _run_hook(runner, args, write):\n    hook_id = args.hook\n    for repo in runner.repositories:\n        for hook_id_in_repo, hook in repo.hooks:\n            if hook_id == hook_id_in_repo:\n                return _run_single_hook(\n                    runner, repo, hook, args, write=write,\n                )\n    else:\n        write('No hook with id `{0}`\\n'.format(hook_id))\n        return 1\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 run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):\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\n    if args.no_stash or args.all_files:\n        ctx = noop_context()\n    else:\n        ctx = staged_files_only(runner.cmd_runner)\n\n    with ctx:\n        if args.hook:\n            return _run_hook(runner, args, write=write)\n        else:\n            return _run_hooks(runner, args, write=write, environ=environ)\n", "path": "pre_commit/commands/run.py"}]}