We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Handle when `core.hooksPath` is set?
As we found in https://github.com/pre-commit/pre-commit-hooks/issues/250, pre-commit (despite being installed) will be silently skipped if `core.hooksPath` is set.

A few options:
- during `pre-commit install`, check this variable and warn
- "" but error
- install into the directory at `core.hooksPath` (but it may be outside the working dir? probably not the best idea to write to it)

--- 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/install_uninstall.py`
Content:
```
1 from __future__ import print_function
2 from __future__ import unicode_literals
3 
4 import io
5 import os.path
6 import sys
7 
8 from pre_commit import output
9 from pre_commit.util import make_executable
10 from pre_commit.util import mkdirp
11 from pre_commit.util import resource_filename
12 
13 
14 # This is used to identify the hook file we install
15 PRIOR_HASHES = (
16     '4d9958c90bc262f47553e2c073f14cfe',
17     'd8ee923c46731b42cd95cc869add4062',
18     '49fd668cb42069aa1b6048464be5d395',
19     '79f09a650522a87b0da915d0d983b2de',
20     'e358c9dae00eac5d06b38dfdb1e33a8c',
21 )
22 CURRENT_HASH = '138fd403232d2ddd5efb44317e38bf03'
23 TEMPLATE_START = '# start templated\n'
24 TEMPLATE_END = '# end templated\n'
25 
26 
27 def is_our_script(filename):
28     if not os.path.exists(filename):
29         return False
30     contents = io.open(filename).read()
31     return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
32 
33 
34 def install(
35         runner, overwrite=False, hooks=False, hook_type='pre-commit',
36         skip_on_missing_conf=False,
37 ):
38     """Install the pre-commit hooks."""
39     hook_path = runner.get_hook_path(hook_type)
40     legacy_path = hook_path + '.legacy'
41 
42     mkdirp(os.path.dirname(hook_path))
43 
44     # If we have an existing hook, move it to pre-commit.legacy
45     if os.path.lexists(hook_path) and not is_our_script(hook_path):
46         os.rename(hook_path, legacy_path)
47 
48     # If we specify overwrite, we simply delete the legacy file
49     if overwrite and os.path.exists(legacy_path):
50         os.remove(legacy_path)
51     elif os.path.exists(legacy_path):
52         output.write_line(
53             'Running in migration mode with existing hooks at {}\n'
54             'Use -f to use only pre-commit.'.format(legacy_path),
55         )
56 
57     params = {
58         'CONFIG': runner.config_file,
59         'HOOK_TYPE': hook_type,
60         'INSTALL_PYTHON': sys.executable,
61         'SKIP_ON_MISSING_CONFIG': skip_on_missing_conf,
62     }
63 
64     with io.open(hook_path, 'w') as hook_file:
65         with io.open(resource_filename('hook-tmpl')) as f:
66             contents = f.read()
67         before, rest = contents.split(TEMPLATE_START)
68         to_template, after = rest.split(TEMPLATE_END)
69 
70         hook_file.write(before + TEMPLATE_START)
71         for line in to_template.splitlines():
72             var = line.split()[0]
73             hook_file.write('{} = {!r}\n'.format(var, params[var]))
74         hook_file.write(TEMPLATE_END + after)
75     make_executable(hook_path)
76 
77     output.write_line('pre-commit installed at {}'.format(hook_path))
78 
79     # If they requested we install all of the hooks, do so.
80     if hooks:
81         install_hooks(runner)
82 
83     return 0
84 
85 
86 def install_hooks(runner):
87     for repository in runner.repositories:
88         repository.require_installed()
89 
90 
91 def uninstall(runner, hook_type='pre-commit'):
92     """Uninstall the pre-commit hooks."""
93     hook_path = runner.get_hook_path(hook_type)
94     legacy_path = hook_path + '.legacy'
95     # If our file doesn't exist or it isn't ours, gtfo.
96     if not os.path.exists(hook_path) or not is_our_script(hook_path):
97         return 0
98 
99     os.remove(hook_path)
100     output.write_line('{} uninstalled'.format(hook_type))
101 
102     if os.path.exists(legacy_path):
103         os.rename(legacy_path, hook_path)
104         output.write_line('Restored previous hooks to {}'.format(hook_path))
105 
106     return 0
107
```
--- 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/install_uninstall.py b/pre_commit/commands/install_uninstall.py
--- a/pre_commit/commands/install_uninstall.py
+++ b/pre_commit/commands/install_uninstall.py
@@ -2,15 +2,19 @@
 from __future__ import unicode_literals
 
 import io
+import logging
 import os.path
 import sys
 
 from pre_commit import output
+from pre_commit.util import cmd_output
 from pre_commit.util import make_executable
 from pre_commit.util import mkdirp
 from pre_commit.util import resource_filename
 
 
+logger = logging.getLogger(__name__)
+
 # This is used to identify the hook file we install
 PRIOR_HASHES = (
     '4d9958c90bc262f47553e2c073f14cfe',
@@ -36,6 +40,13 @@
         skip_on_missing_conf=False,
 ):
     """Install the pre-commit hooks."""
+    if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():
+        logger.error(
+            'Cowardly refusing to install hooks with `core.hooksPath` set.\n'
+            'hint: `git config --unset-all core.hooksPath`',
+        )
+        return 1
+
     hook_path = runner.get_hook_path(hook_type)
     legacy_path = hook_path + '.legacy'

{"golden_diff": "diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py\n--- a/pre_commit/commands/install_uninstall.py\n+++ b/pre_commit/commands/install_uninstall.py\n@@ -2,15 +2,19 @@\n from __future__ import unicode_literals\n \n import io\n+import logging\n import os.path\n import sys\n \n from pre_commit import output\n+from pre_commit.util import cmd_output\n from pre_commit.util import make_executable\n from pre_commit.util import mkdirp\n from pre_commit.util import resource_filename\n \n \n+logger = logging.getLogger(__name__)\n+\n # This is used to identify the hook file we install\n PRIOR_HASHES = (\n     '4d9958c90bc262f47553e2c073f14cfe',\n@@ -36,6 +40,13 @@\n         skip_on_missing_conf=False,\n ):\n     \"\"\"Install the pre-commit hooks.\"\"\"\n+    if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():\n+        logger.error(\n+            'Cowardly refusing to install hooks with `core.hooksPath` set.\\n'\n+            'hint: `git config --unset-all core.hooksPath`',\n+        )\n+        return 1\n+\n     hook_path = runner.get_hook_path(hook_type)\n     legacy_path = hook_path + '.legacy'\n", "issue": "Handle when `core.hooksPath` is set?\nAs we found in https://github.com/pre-commit/pre-commit-hooks/issues/250, pre-commit (despite being installed) will be silently skipped if `core.hooksPath` is set.\r\n\r\nA few options:\r\n- during `pre-commit install`, check this variable and warn\r\n- \"\" but error\r\n- install into the directory at `core.hooksPath` (but it may be outside the working dir? probably not the best idea to write to it)\n", "before_files": [{"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport io\nimport os.path\nimport sys\n\nfrom pre_commit import output\nfrom pre_commit.util import make_executable\nfrom pre_commit.util import mkdirp\nfrom pre_commit.util import resource_filename\n\n\n# This is used to identify the hook file we install\nPRIOR_HASHES = (\n    '4d9958c90bc262f47553e2c073f14cfe',\n    'd8ee923c46731b42cd95cc869add4062',\n    '49fd668cb42069aa1b6048464be5d395',\n    '79f09a650522a87b0da915d0d983b2de',\n    'e358c9dae00eac5d06b38dfdb1e33a8c',\n)\nCURRENT_HASH = '138fd403232d2ddd5efb44317e38bf03'\nTEMPLATE_START = '# start templated\\n'\nTEMPLATE_END = '# end templated\\n'\n\n\ndef is_our_script(filename):\n    if not os.path.exists(filename):\n        return False\n    contents = io.open(filename).read()\n    return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)\n\n\ndef install(\n        runner, overwrite=False, hooks=False, hook_type='pre-commit',\n        skip_on_missing_conf=False,\n):\n    \"\"\"Install the pre-commit hooks.\"\"\"\n    hook_path = runner.get_hook_path(hook_type)\n    legacy_path = hook_path + '.legacy'\n\n    mkdirp(os.path.dirname(hook_path))\n\n    # If we have an existing hook, move it to pre-commit.legacy\n    if os.path.lexists(hook_path) and not is_our_script(hook_path):\n        os.rename(hook_path, legacy_path)\n\n    # If we specify overwrite, we simply delete the legacy file\n    if overwrite and os.path.exists(legacy_path):\n        os.remove(legacy_path)\n    elif os.path.exists(legacy_path):\n        output.write_line(\n            'Running in migration mode with existing hooks at {}\\n'\n            'Use -f to use only pre-commit.'.format(legacy_path),\n        )\n\n    params = {\n        'CONFIG': runner.config_file,\n        'HOOK_TYPE': hook_type,\n        'INSTALL_PYTHON': sys.executable,\n        'SKIP_ON_MISSING_CONFIG': skip_on_missing_conf,\n    }\n\n    with io.open(hook_path, 'w') as hook_file:\n        with io.open(resource_filename('hook-tmpl')) as f:\n            contents = f.read()\n        before, rest = contents.split(TEMPLATE_START)\n        to_template, after = rest.split(TEMPLATE_END)\n\n        hook_file.write(before + TEMPLATE_START)\n        for line in to_template.splitlines():\n            var = line.split()[0]\n            hook_file.write('{} = {!r}\\n'.format(var, params[var]))\n        hook_file.write(TEMPLATE_END + after)\n    make_executable(hook_path)\n\n    output.write_line('pre-commit installed at {}'.format(hook_path))\n\n    # If they requested we install all of the hooks, do so.\n    if hooks:\n        install_hooks(runner)\n\n    return 0\n\n\ndef install_hooks(runner):\n    for repository in runner.repositories:\n        repository.require_installed()\n\n\ndef uninstall(runner, hook_type='pre-commit'):\n    \"\"\"Uninstall the pre-commit hooks.\"\"\"\n    hook_path = runner.get_hook_path(hook_type)\n    legacy_path = hook_path + '.legacy'\n    # If our file doesn't exist or it isn't ours, gtfo.\n    if not os.path.exists(hook_path) or not is_our_script(hook_path):\n        return 0\n\n    os.remove(hook_path)\n    output.write_line('{} uninstalled'.format(hook_type))\n\n    if os.path.exists(legacy_path):\n        os.rename(legacy_path, hook_path)\n        output.write_line('Restored previous hooks to {}'.format(hook_path))\n\n    return 0\n", "path": "pre_commit/commands/install_uninstall.py"}], "after_files": [{"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport io\nimport logging\nimport os.path\nimport sys\n\nfrom pre_commit import output\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import make_executable\nfrom pre_commit.util import mkdirp\nfrom pre_commit.util import resource_filename\n\n\nlogger = logging.getLogger(__name__)\n\n# This is used to identify the hook file we install\nPRIOR_HASHES = (\n    '4d9958c90bc262f47553e2c073f14cfe',\n    'd8ee923c46731b42cd95cc869add4062',\n    '49fd668cb42069aa1b6048464be5d395',\n    '79f09a650522a87b0da915d0d983b2de',\n    'e358c9dae00eac5d06b38dfdb1e33a8c',\n)\nCURRENT_HASH = '138fd403232d2ddd5efb44317e38bf03'\nTEMPLATE_START = '# start templated\\n'\nTEMPLATE_END = '# end templated\\n'\n\n\ndef is_our_script(filename):\n    if not os.path.exists(filename):\n        return False\n    contents = io.open(filename).read()\n    return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)\n\n\ndef install(\n        runner, overwrite=False, hooks=False, hook_type='pre-commit',\n        skip_on_missing_conf=False,\n):\n    \"\"\"Install the pre-commit hooks.\"\"\"\n    if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():\n        logger.error(\n            'Cowardly refusing to install hooks with `core.hooksPath` set.\\n'\n            'hint: `git config --unset-all core.hooksPath`',\n        )\n        return 1\n\n    hook_path = runner.get_hook_path(hook_type)\n    legacy_path = hook_path + '.legacy'\n\n    mkdirp(os.path.dirname(hook_path))\n\n    # If we have an existing hook, move it to pre-commit.legacy\n    if os.path.lexists(hook_path) and not is_our_script(hook_path):\n        os.rename(hook_path, legacy_path)\n\n    # If we specify overwrite, we simply delete the legacy file\n    if overwrite and os.path.exists(legacy_path):\n        os.remove(legacy_path)\n    elif os.path.exists(legacy_path):\n        output.write_line(\n            'Running in migration mode with existing hooks at {}\\n'\n            'Use -f to use only pre-commit.'.format(legacy_path),\n        )\n\n    params = {\n        'CONFIG': runner.config_file,\n        'HOOK_TYPE': hook_type,\n        'INSTALL_PYTHON': sys.executable,\n        'SKIP_ON_MISSING_CONFIG': skip_on_missing_conf,\n    }\n\n    with io.open(hook_path, 'w') as hook_file:\n        with io.open(resource_filename('hook-tmpl')) as f:\n            contents = f.read()\n        before, rest = contents.split(TEMPLATE_START)\n        to_template, after = rest.split(TEMPLATE_END)\n\n        hook_file.write(before + TEMPLATE_START)\n        for line in to_template.splitlines():\n            var = line.split()[0]\n            hook_file.write('{} = {!r}\\n'.format(var, params[var]))\n        hook_file.write(TEMPLATE_END + after)\n    make_executable(hook_path)\n\n    output.write_line('pre-commit installed at {}'.format(hook_path))\n\n    # If they requested we install all of the hooks, do so.\n    if hooks:\n        install_hooks(runner)\n\n    return 0\n\n\ndef install_hooks(runner):\n    for repository in runner.repositories:\n        repository.require_installed()\n\n\ndef uninstall(runner, hook_type='pre-commit'):\n    \"\"\"Uninstall the pre-commit hooks.\"\"\"\n    hook_path = runner.get_hook_path(hook_type)\n    legacy_path = hook_path + '.legacy'\n    # If our file doesn't exist or it isn't ours, gtfo.\n    if not os.path.exists(hook_path) or not is_our_script(hook_path):\n        return 0\n\n    os.remove(hook_path)\n    output.write_line('{} uninstalled'.format(hook_type))\n\n    if os.path.exists(legacy_path):\n        os.rename(legacy_path, hook_path)\n        output.write_line('Restored previous hooks to {}'.format(hook_path))\n\n    return 0\n", "path": "pre_commit/commands/install_uninstall.py"}]}