We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
cygwin python checking should happen after setup code
Regressed as part of #436

Before:

```
$ ./pre-commit/venv_cygwin_python/bin/pre-commit clean
An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?
Check the log at ~/.pre-commit/pre-commit.log
```

Current master:

```
$ ./pre-commit/venv_cygwin_python/bin/pre-commit clean
An unexpected error has occurred: CalledProcessError: Command: ('/usr/bin/git', 'rev-parse', '--show-toplevel')
Return code: 128
Expected return code: 0
Output: (none)
Errors:
    fatal: Not a git repository (or any of the parent directories): .git


Check the log at ~/.pre-commit/pre-commit.log
```

--- 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/main.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 import argparse
4 import os
5 import sys
6 
7 import pkg_resources
8 
9 from pre_commit import color
10 from pre_commit import five
11 from pre_commit import git
12 from pre_commit.commands.autoupdate import autoupdate
13 from pre_commit.commands.clean import clean
14 from pre_commit.commands.install_uninstall import install
15 from pre_commit.commands.install_uninstall import uninstall
16 from pre_commit.commands.run import run
17 from pre_commit.error_handler import error_handler
18 from pre_commit.logging_handler import add_logging_handler
19 from pre_commit.runner import Runner
20 
21 
22 # https://github.com/pre-commit/pre-commit/issues/217
23 # On OSX, making a virtualenv using pyvenv at . causes `virtualenv` and `pip`
24 # to install packages to the wrong place.  We don't want anything to deal with
25 # pyvenv
26 os.environ.pop('__PYVENV_LAUNCHER__', None)
27 
28 
29 def _add_color_option(parser):
30     parser.add_argument(
31         '--color', default='auto', type=color.use_color,
32         metavar='{' + ','.join(color.COLOR_CHOICES) + '}',
33         help='Whether to use color in output.  Defaults to `%(default)s`.',
34     )
35 
36 
37 def main(argv=None):
38     argv = argv if argv is not None else sys.argv[1:]
39     argv = [five.to_text(arg) for arg in argv]
40     parser = argparse.ArgumentParser()
41 
42     # http://stackoverflow.com/a/8521644/812183
43     parser.add_argument(
44         '-V', '--version',
45         action='version',
46         version='%(prog)s {}'.format(
47             pkg_resources.get_distribution('pre-commit').version
48         )
49     )
50 
51     subparsers = parser.add_subparsers(dest='command')
52 
53     install_parser = subparsers.add_parser(
54         'install', help='Install the pre-commit script.',
55     )
56     _add_color_option(install_parser)
57     install_parser.add_argument(
58         '-f', '--overwrite', action='store_true',
59         help='Overwrite existing hooks / remove migration mode.',
60     )
61     install_parser.add_argument(
62         '--install-hooks', action='store_true',
63         help=(
64             'Whether to install hook environments for all environments '
65             'in the config file.'
66         ),
67     )
68     install_parser.add_argument(
69         '-t', '--hook-type', choices=('pre-commit', 'pre-push'),
70         default='pre-commit',
71     )
72 
73     uninstall_parser = subparsers.add_parser(
74         'uninstall', help='Uninstall the pre-commit script.',
75     )
76     _add_color_option(uninstall_parser)
77     uninstall_parser.add_argument(
78         '-t', '--hook-type', choices=('pre-commit', 'pre-push'),
79         default='pre-commit',
80     )
81 
82     clean_parser = subparsers.add_parser(
83         'clean', help='Clean out pre-commit files.',
84     )
85     _add_color_option(clean_parser)
86 
87     autoupdate_parser = subparsers.add_parser(
88         'autoupdate',
89         help="Auto-update pre-commit config to the latest repos' versions.",
90     )
91     _add_color_option(autoupdate_parser)
92 
93     run_parser = subparsers.add_parser('run', help='Run hooks.')
94     _add_color_option(run_parser)
95     run_parser.add_argument('hook', nargs='?', help='A single hook-id to run')
96     run_parser.add_argument(
97         '--no-stash', default=False, action='store_true',
98         help='Use this option to prevent auto stashing of unstaged files.',
99     )
100     run_parser.add_argument(
101         '--verbose', '-v', action='store_true', default=False,
102     )
103     run_parser.add_argument(
104         '--origin', '-o',
105         help="The origin branch's commit_id when using `git push`.",
106     )
107     run_parser.add_argument(
108         '--source', '-s',
109         help="The remote branch's commit_id when using `git push`.",
110     )
111     run_parser.add_argument(
112         '--allow-unstaged-config', default=False, action='store_true',
113         help=(
114             'Allow an unstaged config to be present.  Note that this will '
115             'be stashed before parsing unless --no-stash is specified.'
116         ),
117     )
118     run_parser.add_argument(
119         '--hook-stage', choices=('commit', 'push'), default='commit',
120         help='The stage during which the hook is fired e.g. commit or push.',
121     )
122     run_mutex_group = run_parser.add_mutually_exclusive_group(required=False)
123     run_mutex_group.add_argument(
124         '--all-files', '-a', action='store_true', default=False,
125         help='Run on all the files in the repo.  Implies --no-stash.',
126     )
127     run_mutex_group.add_argument(
128         '--files', nargs='*', default=[],
129         help='Specific filenames to run hooks on.',
130     )
131 
132     help = subparsers.add_parser(
133         'help', help='Show help for a specific command.',
134     )
135     help.add_argument('help_cmd', nargs='?', help='Command to show help for.')
136 
137     # Argparse doesn't really provide a way to use a `default` subparser
138     if len(argv) == 0:
139         argv = ['run']
140     args = parser.parse_args(argv)
141     if args.command == 'run':
142         args.files = [
143             os.path.relpath(os.path.abspath(filename), git.get_root())
144             for filename in args.files
145         ]
146 
147     if args.command == 'help':
148         if args.help_cmd:
149             parser.parse_args([args.help_cmd, '--help'])
150         else:
151             parser.parse_args(['--help'])
152 
153     with error_handler():
154         add_logging_handler(args.color)
155         git.check_for_cygwin_mismatch()
156         runner = Runner.create()
157 
158         if args.command == 'install':
159             return install(
160                 runner, overwrite=args.overwrite, hooks=args.install_hooks,
161                 hook_type=args.hook_type,
162             )
163         elif args.command == 'uninstall':
164             return uninstall(runner, hook_type=args.hook_type)
165         elif args.command == 'clean':
166             return clean(runner)
167         elif args.command == 'autoupdate':
168             return autoupdate(runner)
169         elif args.command == 'run':
170             return run(runner, args)
171         else:
172             raise NotImplementedError(
173                 'Command {} not implemented.'.format(args.command)
174             )
175 
176         raise AssertionError(
177             'Command {} failed to exit with a returncode'.format(args.command)
178         )
179 
180 
181 if __name__ == '__main__':
182     exit(main())
183
```
--- 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/main.py b/pre_commit/main.py
--- a/pre_commit/main.py
+++ b/pre_commit/main.py
@@ -152,8 +152,8 @@
 
     with error_handler():
         add_logging_handler(args.color)
-        git.check_for_cygwin_mismatch()
         runner = Runner.create()
+        git.check_for_cygwin_mismatch()
 
         if args.command == 'install':
             return install(

{"golden_diff": "diff --git a/pre_commit/main.py b/pre_commit/main.py\n--- a/pre_commit/main.py\n+++ b/pre_commit/main.py\n@@ -152,8 +152,8 @@\n \n     with error_handler():\n         add_logging_handler(args.color)\n-        git.check_for_cygwin_mismatch()\n         runner = Runner.create()\n+        git.check_for_cygwin_mismatch()\n \n         if args.command == 'install':\n             return install(\n", "issue": "cygwin python checking should happen after setup code\nRegressed as part of #436\r\n\r\nBefore:\r\n\r\n```\r\n$ ./pre-commit/venv_cygwin_python/bin/pre-commit clean\r\nAn error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?\r\nCheck the log at ~/.pre-commit/pre-commit.log\r\n```\r\n\r\nCurrent master:\r\n\r\n```\r\n$ ./pre-commit/venv_cygwin_python/bin/pre-commit clean\r\nAn unexpected error has occurred: CalledProcessError: Command: ('/usr/bin/git', 'rev-parse', '--show-toplevel')\r\nReturn code: 128\r\nExpected return code: 0\r\nOutput: (none)\r\nErrors:\r\n    fatal: Not a git repository (or any of the parent directories): .git\r\n\r\n\r\nCheck the log at ~/.pre-commit/pre-commit.log\r\n```\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport argparse\nimport os\nimport sys\n\nimport pkg_resources\n\nfrom pre_commit import color\nfrom pre_commit import five\nfrom pre_commit import git\nfrom pre_commit.commands.autoupdate import autoupdate\nfrom pre_commit.commands.clean import clean\nfrom pre_commit.commands.install_uninstall import install\nfrom pre_commit.commands.install_uninstall import uninstall\nfrom pre_commit.commands.run import run\nfrom pre_commit.error_handler import error_handler\nfrom pre_commit.logging_handler import add_logging_handler\nfrom pre_commit.runner import Runner\n\n\n# https://github.com/pre-commit/pre-commit/issues/217\n# On OSX, making a virtualenv using pyvenv at . causes `virtualenv` and `pip`\n# to install packages to the wrong place.  We don't want anything to deal with\n# pyvenv\nos.environ.pop('__PYVENV_LAUNCHER__', None)\n\n\ndef _add_color_option(parser):\n    parser.add_argument(\n        '--color', default='auto', type=color.use_color,\n        metavar='{' + ','.join(color.COLOR_CHOICES) + '}',\n        help='Whether to use color in output.  Defaults to `%(default)s`.',\n    )\n\n\ndef main(argv=None):\n    argv = argv if argv is not None else sys.argv[1:]\n    argv = [five.to_text(arg) for arg in argv]\n    parser = argparse.ArgumentParser()\n\n    # http://stackoverflow.com/a/8521644/812183\n    parser.add_argument(\n        '-V', '--version',\n        action='version',\n        version='%(prog)s {}'.format(\n            pkg_resources.get_distribution('pre-commit').version\n        )\n    )\n\n    subparsers = parser.add_subparsers(dest='command')\n\n    install_parser = subparsers.add_parser(\n        'install', help='Install the pre-commit script.',\n    )\n    _add_color_option(install_parser)\n    install_parser.add_argument(\n        '-f', '--overwrite', action='store_true',\n        help='Overwrite existing hooks / remove migration mode.',\n    )\n    install_parser.add_argument(\n        '--install-hooks', action='store_true',\n        help=(\n            'Whether to install hook environments for all environments '\n            'in the config file.'\n        ),\n    )\n    install_parser.add_argument(\n        '-t', '--hook-type', choices=('pre-commit', 'pre-push'),\n        default='pre-commit',\n    )\n\n    uninstall_parser = subparsers.add_parser(\n        'uninstall', help='Uninstall the pre-commit script.',\n    )\n    _add_color_option(uninstall_parser)\n    uninstall_parser.add_argument(\n        '-t', '--hook-type', choices=('pre-commit', 'pre-push'),\n        default='pre-commit',\n    )\n\n    clean_parser = subparsers.add_parser(\n        'clean', help='Clean out pre-commit files.',\n    )\n    _add_color_option(clean_parser)\n\n    autoupdate_parser = subparsers.add_parser(\n        'autoupdate',\n        help=\"Auto-update pre-commit config to the latest repos' versions.\",\n    )\n    _add_color_option(autoupdate_parser)\n\n    run_parser = subparsers.add_parser('run', help='Run hooks.')\n    _add_color_option(run_parser)\n    run_parser.add_argument('hook', nargs='?', help='A single hook-id to run')\n    run_parser.add_argument(\n        '--no-stash', default=False, action='store_true',\n        help='Use this option to prevent auto stashing of unstaged files.',\n    )\n    run_parser.add_argument(\n        '--verbose', '-v', action='store_true', default=False,\n    )\n    run_parser.add_argument(\n        '--origin', '-o',\n        help=\"The origin branch's commit_id when using `git push`.\",\n    )\n    run_parser.add_argument(\n        '--source', '-s',\n        help=\"The remote branch's commit_id when using `git push`.\",\n    )\n    run_parser.add_argument(\n        '--allow-unstaged-config', default=False, action='store_true',\n        help=(\n            'Allow an unstaged config to be present.  Note that this will '\n            'be stashed before parsing unless --no-stash is specified.'\n        ),\n    )\n    run_parser.add_argument(\n        '--hook-stage', choices=('commit', 'push'), default='commit',\n        help='The stage during which the hook is fired e.g. commit or push.',\n    )\n    run_mutex_group = run_parser.add_mutually_exclusive_group(required=False)\n    run_mutex_group.add_argument(\n        '--all-files', '-a', action='store_true', default=False,\n        help='Run on all the files in the repo.  Implies --no-stash.',\n    )\n    run_mutex_group.add_argument(\n        '--files', nargs='*', default=[],\n        help='Specific filenames to run hooks on.',\n    )\n\n    help = subparsers.add_parser(\n        'help', help='Show help for a specific command.',\n    )\n    help.add_argument('help_cmd', nargs='?', help='Command to show help for.')\n\n    # Argparse doesn't really provide a way to use a `default` subparser\n    if len(argv) == 0:\n        argv = ['run']\n    args = parser.parse_args(argv)\n    if args.command == 'run':\n        args.files = [\n            os.path.relpath(os.path.abspath(filename), git.get_root())\n            for filename in args.files\n        ]\n\n    if args.command == 'help':\n        if args.help_cmd:\n            parser.parse_args([args.help_cmd, '--help'])\n        else:\n            parser.parse_args(['--help'])\n\n    with error_handler():\n        add_logging_handler(args.color)\n        git.check_for_cygwin_mismatch()\n        runner = Runner.create()\n\n        if args.command == 'install':\n            return install(\n                runner, overwrite=args.overwrite, hooks=args.install_hooks,\n                hook_type=args.hook_type,\n            )\n        elif args.command == 'uninstall':\n            return uninstall(runner, hook_type=args.hook_type)\n        elif args.command == 'clean':\n            return clean(runner)\n        elif args.command == 'autoupdate':\n            return autoupdate(runner)\n        elif args.command == 'run':\n            return run(runner, args)\n        else:\n            raise NotImplementedError(\n                'Command {} not implemented.'.format(args.command)\n            )\n\n        raise AssertionError(\n            'Command {} failed to exit with a returncode'.format(args.command)\n        )\n\n\nif __name__ == '__main__':\n    exit(main())\n", "path": "pre_commit/main.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport argparse\nimport os\nimport sys\n\nimport pkg_resources\n\nfrom pre_commit import color\nfrom pre_commit import five\nfrom pre_commit import git\nfrom pre_commit.commands.autoupdate import autoupdate\nfrom pre_commit.commands.clean import clean\nfrom pre_commit.commands.install_uninstall import install\nfrom pre_commit.commands.install_uninstall import uninstall\nfrom pre_commit.commands.run import run\nfrom pre_commit.error_handler import error_handler\nfrom pre_commit.logging_handler import add_logging_handler\nfrom pre_commit.runner import Runner\n\n\n# https://github.com/pre-commit/pre-commit/issues/217\n# On OSX, making a virtualenv using pyvenv at . causes `virtualenv` and `pip`\n# to install packages to the wrong place.  We don't want anything to deal with\n# pyvenv\nos.environ.pop('__PYVENV_LAUNCHER__', None)\n\n\ndef _add_color_option(parser):\n    parser.add_argument(\n        '--color', default='auto', type=color.use_color,\n        metavar='{' + ','.join(color.COLOR_CHOICES) + '}',\n        help='Whether to use color in output.  Defaults to `%(default)s`.',\n    )\n\n\ndef main(argv=None):\n    argv = argv if argv is not None else sys.argv[1:]\n    argv = [five.to_text(arg) for arg in argv]\n    parser = argparse.ArgumentParser()\n\n    # http://stackoverflow.com/a/8521644/812183\n    parser.add_argument(\n        '-V', '--version',\n        action='version',\n        version='%(prog)s {}'.format(\n            pkg_resources.get_distribution('pre-commit').version\n        )\n    )\n\n    subparsers = parser.add_subparsers(dest='command')\n\n    install_parser = subparsers.add_parser(\n        'install', help='Install the pre-commit script.',\n    )\n    _add_color_option(install_parser)\n    install_parser.add_argument(\n        '-f', '--overwrite', action='store_true',\n        help='Overwrite existing hooks / remove migration mode.',\n    )\n    install_parser.add_argument(\n        '--install-hooks', action='store_true',\n        help=(\n            'Whether to install hook environments for all environments '\n            'in the config file.'\n        ),\n    )\n    install_parser.add_argument(\n        '-t', '--hook-type', choices=('pre-commit', 'pre-push'),\n        default='pre-commit',\n    )\n\n    uninstall_parser = subparsers.add_parser(\n        'uninstall', help='Uninstall the pre-commit script.',\n    )\n    _add_color_option(uninstall_parser)\n    uninstall_parser.add_argument(\n        '-t', '--hook-type', choices=('pre-commit', 'pre-push'),\n        default='pre-commit',\n    )\n\n    clean_parser = subparsers.add_parser(\n        'clean', help='Clean out pre-commit files.',\n    )\n    _add_color_option(clean_parser)\n\n    autoupdate_parser = subparsers.add_parser(\n        'autoupdate',\n        help=\"Auto-update pre-commit config to the latest repos' versions.\",\n    )\n    _add_color_option(autoupdate_parser)\n\n    run_parser = subparsers.add_parser('run', help='Run hooks.')\n    _add_color_option(run_parser)\n    run_parser.add_argument('hook', nargs='?', help='A single hook-id to run')\n    run_parser.add_argument(\n        '--no-stash', default=False, action='store_true',\n        help='Use this option to prevent auto stashing of unstaged files.',\n    )\n    run_parser.add_argument(\n        '--verbose', '-v', action='store_true', default=False,\n    )\n    run_parser.add_argument(\n        '--origin', '-o',\n        help=\"The origin branch's commit_id when using `git push`.\",\n    )\n    run_parser.add_argument(\n        '--source', '-s',\n        help=\"The remote branch's commit_id when using `git push`.\",\n    )\n    run_parser.add_argument(\n        '--allow-unstaged-config', default=False, action='store_true',\n        help=(\n            'Allow an unstaged config to be present.  Note that this will '\n            'be stashed before parsing unless --no-stash is specified.'\n        ),\n    )\n    run_parser.add_argument(\n        '--hook-stage', choices=('commit', 'push'), default='commit',\n        help='The stage during which the hook is fired e.g. commit or push.',\n    )\n    run_mutex_group = run_parser.add_mutually_exclusive_group(required=False)\n    run_mutex_group.add_argument(\n        '--all-files', '-a', action='store_true', default=False,\n        help='Run on all the files in the repo.  Implies --no-stash.',\n    )\n    run_mutex_group.add_argument(\n        '--files', nargs='*', default=[],\n        help='Specific filenames to run hooks on.',\n    )\n\n    help = subparsers.add_parser(\n        'help', help='Show help for a specific command.',\n    )\n    help.add_argument('help_cmd', nargs='?', help='Command to show help for.')\n\n    # Argparse doesn't really provide a way to use a `default` subparser\n    if len(argv) == 0:\n        argv = ['run']\n    args = parser.parse_args(argv)\n    if args.command == 'run':\n        args.files = [\n            os.path.relpath(os.path.abspath(filename), git.get_root())\n            for filename in args.files\n        ]\n\n    if args.command == 'help':\n        if args.help_cmd:\n            parser.parse_args([args.help_cmd, '--help'])\n        else:\n            parser.parse_args(['--help'])\n\n    with error_handler():\n        add_logging_handler(args.color)\n        runner = Runner.create()\n        git.check_for_cygwin_mismatch()\n\n        if args.command == 'install':\n            return install(\n                runner, overwrite=args.overwrite, hooks=args.install_hooks,\n                hook_type=args.hook_type,\n            )\n        elif args.command == 'uninstall':\n            return uninstall(runner, hook_type=args.hook_type)\n        elif args.command == 'clean':\n            return clean(runner)\n        elif args.command == 'autoupdate':\n            return autoupdate(runner)\n        elif args.command == 'run':\n            return run(runner, args)\n        else:\n            raise NotImplementedError(\n                'Command {} not implemented.'.format(args.command)\n            )\n\n        raise AssertionError(\n            'Command {} failed to exit with a returncode'.format(args.command)\n        )\n\n\nif __name__ == '__main__':\n    exit(main())\n", "path": "pre_commit/main.py"}]}