We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
recursive submodule support for `language: golang`
I added this hook in `pre-commit-hooks.yaml` in `https://github.com/google/go-jsonnet`, and then when I try to use this hook as:
```
repos:
  - repo: https://github.com/google/go-jsonnet
    rev: 4a3144a417b7eb9b1f7e56741a9e72f3155de3fa
    hooks:
      - id: jsonnet-format
```
then I see following error.

```
Traceback (most recent call last):
  File "/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/main.py", line 378, in main
    return run(args.config, store, args)
  File "/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/commands/run.py", line 403, in run
    install_hook_envs(hooks, store)
  File "/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/repository.py", line 224, in install_hook_envs
    _hook_install(hook)
  File "/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/repository.py", line 82, in _hook_install
    lang.install_environment(
  File "/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/languages/golang.py", line 81, in install_environment
    cmd_output_b('go', 'get', './...', cwd=repo_src_dir, env=env)
  File "/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/local/bin/go', 'get', './...')
return code: 2
expected return code: 0
stdout: (none)
stderr:
    go: downloading github.com/sergi/go-diff v1.1.0
    go: downloading github.com/fatih/color v1.9.0
    go: downloading github.com/mattn/go-colorable v0.1.4
    go: downloading github.com/mattn/go-isatty v0.0.11
    go: downloading golang.org/x/sys v0.0.0-20191026070338-33540a1f6037
    # github.com/google/go-jsonnet/c-bindings
    libjsonnet.cpp:5:14: fatal error: 'libjsonnet.h' file not found

```
Any idea? Thanks.

_Originally posted by @gaurav517 in https://github.com/pre-commit/pre-commit/issues/1785#issuecomment-774486062_

--- 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/languages/golang.py`
Content:
```
1 import contextlib
2 import os.path
3 import sys
4 from typing import Generator
5 from typing import Sequence
6 from typing import Tuple
7 
8 import pre_commit.constants as C
9 from pre_commit import git
10 from pre_commit.envcontext import envcontext
11 from pre_commit.envcontext import PatchesT
12 from pre_commit.envcontext import Var
13 from pre_commit.hook import Hook
14 from pre_commit.languages import helpers
15 from pre_commit.prefix import Prefix
16 from pre_commit.util import clean_path_on_failure
17 from pre_commit.util import cmd_output
18 from pre_commit.util import cmd_output_b
19 from pre_commit.util import rmtree
20 
21 ENVIRONMENT_DIR = 'golangenv'
22 get_default_version = helpers.basic_get_default_version
23 healthy = helpers.basic_healthy
24 
25 
26 def get_env_patch(venv: str) -> PatchesT:
27     return (
28         ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),
29     )
30 
31 
32 @contextlib.contextmanager
33 def in_env(prefix: Prefix) -> Generator[None, None, None]:
34     envdir = prefix.path(
35         helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),
36     )
37     with envcontext(get_env_patch(envdir)):
38         yield
39 
40 
41 def guess_go_dir(remote_url: str) -> str:
42     if remote_url.endswith('.git'):
43         remote_url = remote_url[:-1 * len('.git')]
44     looks_like_url = (
45         not remote_url.startswith('file://') and
46         ('//' in remote_url or '@' in remote_url)
47     )
48     remote_url = remote_url.replace(':', '/')
49     if looks_like_url:
50         _, _, remote_url = remote_url.rpartition('//')
51         _, _, remote_url = remote_url.rpartition('@')
52         return remote_url
53     else:
54         return 'unknown_src_dir'
55 
56 
57 def install_environment(
58         prefix: Prefix,
59         version: str,
60         additional_dependencies: Sequence[str],
61 ) -> None:
62     helpers.assert_version_default('golang', version)
63     directory = prefix.path(
64         helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),
65     )
66 
67     with clean_path_on_failure(directory):
68         remote = git.get_remote_url(prefix.prefix_dir)
69         repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote))
70 
71         # Clone into the goenv we'll create
72         helpers.run_setup_cmd(prefix, ('git', 'clone', '.', repo_src_dir))
73 
74         if sys.platform == 'cygwin':  # pragma: no cover
75             _, gopath, _ = cmd_output('cygpath', '-w', directory)
76             gopath = gopath.strip()
77         else:
78             gopath = directory
79         env = dict(os.environ, GOPATH=gopath)
80         env.pop('GOBIN', None)
81         cmd_output_b('go', 'get', './...', cwd=repo_src_dir, env=env)
82         for dependency in additional_dependencies:
83             cmd_output_b('go', 'get', dependency, cwd=repo_src_dir, env=env)
84         # Same some disk space, we don't need these after installation
85         rmtree(prefix.path(directory, 'src'))
86         pkgdir = prefix.path(directory, 'pkg')
87         if os.path.exists(pkgdir):  # pragma: no cover (go<1.10)
88             rmtree(pkgdir)
89 
90 
91 def run_hook(
92         hook: Hook,
93         file_args: Sequence[str],
94         color: bool,
95 ) -> Tuple[int, bytes]:
96     with in_env(hook.prefix):
97         return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
98
```
--- 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/languages/golang.py b/pre_commit/languages/golang.py
--- a/pre_commit/languages/golang.py
+++ b/pre_commit/languages/golang.py
@@ -69,7 +69,8 @@
         repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote))
 
         # Clone into the goenv we'll create
-        helpers.run_setup_cmd(prefix, ('git', 'clone', '.', repo_src_dir))
+        cmd = ('git', 'clone', '--recursive', '.', repo_src_dir)
+        helpers.run_setup_cmd(prefix, cmd)
 
         if sys.platform == 'cygwin':  # pragma: no cover
             _, gopath, _ = cmd_output('cygpath', '-w', directory)

{"golden_diff": "diff --git a/pre_commit/languages/golang.py b/pre_commit/languages/golang.py\n--- a/pre_commit/languages/golang.py\n+++ b/pre_commit/languages/golang.py\n@@ -69,7 +69,8 @@\n         repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote))\n \n         # Clone into the goenv we'll create\n-        helpers.run_setup_cmd(prefix, ('git', 'clone', '.', repo_src_dir))\n+        cmd = ('git', 'clone', '--recursive', '.', repo_src_dir)\n+        helpers.run_setup_cmd(prefix, cmd)\n \n         if sys.platform == 'cygwin':  # pragma: no cover\n             _, gopath, _ = cmd_output('cygpath', '-w', directory)\n", "issue": "recursive submodule support for `language: golang`\nI added this hook in `pre-commit-hooks.yaml` in `https://github.com/google/go-jsonnet`, and then when I try to use this hook as:\r\n```\r\nrepos:\r\n  - repo: https://github.com/google/go-jsonnet\r\n    rev: 4a3144a417b7eb9b1f7e56741a9e72f3155de3fa\r\n    hooks:\r\n      - id: jsonnet-format\r\n```\r\nthen I see following error.\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/error_handler.py\", line 65, in error_handler\r\n    yield\r\n  File \"/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/main.py\", line 378, in main\r\n    return run(args.config, store, args)\r\n  File \"/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/commands/run.py\", line 403, in run\r\n    install_hook_envs(hooks, store)\r\n  File \"/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/repository.py\", line 224, in install_hook_envs\r\n    _hook_install(hook)\r\n  File \"/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/repository.py\", line 82, in _hook_install\r\n    lang.install_environment(\r\n  File \"/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/languages/golang.py\", line 81, in install_environment\r\n    cmd_output_b('go', 'get', './...', cwd=repo_src_dir, env=env)\r\n  File \"/usr/local/Cellar/pre-commit/2.10.0/libexec/lib/python3.9/site-packages/pre_commit/util.py\", line 154, in cmd_output_b\r\n    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)\r\npre_commit.util.CalledProcessError: command: ('/usr/local/bin/go', 'get', './...')\r\nreturn code: 2\r\nexpected return code: 0\r\nstdout: (none)\r\nstderr:\r\n    go: downloading github.com/sergi/go-diff v1.1.0\r\n    go: downloading github.com/fatih/color v1.9.0\r\n    go: downloading github.com/mattn/go-colorable v0.1.4\r\n    go: downloading github.com/mattn/go-isatty v0.0.11\r\n    go: downloading golang.org/x/sys v0.0.0-20191026070338-33540a1f6037\r\n    # github.com/google/go-jsonnet/c-bindings\r\n    libjsonnet.cpp:5:14: fatal error: 'libjsonnet.h' file not found\r\n\r\n```\r\nAny idea? Thanks.\r\n\r\n_Originally posted by @gaurav517 in https://github.com/pre-commit/pre-commit/issues/1785#issuecomment-774486062_\n", "before_files": [{"content": "import contextlib\nimport os.path\nimport sys\nfrom typing import Generator\nfrom typing import Sequence\nfrom typing import Tuple\n\nimport pre_commit.constants as C\nfrom pre_commit import git\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import PatchesT\nfrom pre_commit.envcontext import Var\nfrom pre_commit.hook import Hook\nfrom pre_commit.languages import helpers\nfrom pre_commit.prefix import Prefix\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import cmd_output_b\nfrom pre_commit.util import rmtree\n\nENVIRONMENT_DIR = 'golangenv'\nget_default_version = helpers.basic_get_default_version\nhealthy = helpers.basic_healthy\n\n\ndef get_env_patch(venv: str) -> PatchesT:\n    return (\n        ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),\n    )\n\n\n@contextlib.contextmanager\ndef in_env(prefix: Prefix) -> Generator[None, None, None]:\n    envdir = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),\n    )\n    with envcontext(get_env_patch(envdir)):\n        yield\n\n\ndef guess_go_dir(remote_url: str) -> str:\n    if remote_url.endswith('.git'):\n        remote_url = remote_url[:-1 * len('.git')]\n    looks_like_url = (\n        not remote_url.startswith('file://') and\n        ('//' in remote_url or '@' in remote_url)\n    )\n    remote_url = remote_url.replace(':', '/')\n    if looks_like_url:\n        _, _, remote_url = remote_url.rpartition('//')\n        _, _, remote_url = remote_url.rpartition('@')\n        return remote_url\n    else:\n        return 'unknown_src_dir'\n\n\ndef install_environment(\n        prefix: Prefix,\n        version: str,\n        additional_dependencies: Sequence[str],\n) -> None:\n    helpers.assert_version_default('golang', version)\n    directory = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),\n    )\n\n    with clean_path_on_failure(directory):\n        remote = git.get_remote_url(prefix.prefix_dir)\n        repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote))\n\n        # Clone into the goenv we'll create\n        helpers.run_setup_cmd(prefix, ('git', 'clone', '.', repo_src_dir))\n\n        if sys.platform == 'cygwin':  # pragma: no cover\n            _, gopath, _ = cmd_output('cygpath', '-w', directory)\n            gopath = gopath.strip()\n        else:\n            gopath = directory\n        env = dict(os.environ, GOPATH=gopath)\n        env.pop('GOBIN', None)\n        cmd_output_b('go', 'get', './...', cwd=repo_src_dir, env=env)\n        for dependency in additional_dependencies:\n            cmd_output_b('go', 'get', dependency, cwd=repo_src_dir, env=env)\n        # Same some disk space, we don't need these after installation\n        rmtree(prefix.path(directory, 'src'))\n        pkgdir = prefix.path(directory, 'pkg')\n        if os.path.exists(pkgdir):  # pragma: no cover (go<1.10)\n            rmtree(pkgdir)\n\n\ndef run_hook(\n        hook: Hook,\n        file_args: Sequence[str],\n        color: bool,\n) -> Tuple[int, bytes]:\n    with in_env(hook.prefix):\n        return helpers.run_xargs(hook, hook.cmd, file_args, color=color)\n", "path": "pre_commit/languages/golang.py"}], "after_files": [{"content": "import contextlib\nimport os.path\nimport sys\nfrom typing import Generator\nfrom typing import Sequence\nfrom typing import Tuple\n\nimport pre_commit.constants as C\nfrom pre_commit import git\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import PatchesT\nfrom pre_commit.envcontext import Var\nfrom pre_commit.hook import Hook\nfrom pre_commit.languages import helpers\nfrom pre_commit.prefix import Prefix\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\nfrom pre_commit.util import cmd_output_b\nfrom pre_commit.util import rmtree\n\nENVIRONMENT_DIR = 'golangenv'\nget_default_version = helpers.basic_get_default_version\nhealthy = helpers.basic_healthy\n\n\ndef get_env_patch(venv: str) -> PatchesT:\n    return (\n        ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),\n    )\n\n\n@contextlib.contextmanager\ndef in_env(prefix: Prefix) -> Generator[None, None, None]:\n    envdir = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),\n    )\n    with envcontext(get_env_patch(envdir)):\n        yield\n\n\ndef guess_go_dir(remote_url: str) -> str:\n    if remote_url.endswith('.git'):\n        remote_url = remote_url[:-1 * len('.git')]\n    looks_like_url = (\n        not remote_url.startswith('file://') and\n        ('//' in remote_url or '@' in remote_url)\n    )\n    remote_url = remote_url.replace(':', '/')\n    if looks_like_url:\n        _, _, remote_url = remote_url.rpartition('//')\n        _, _, remote_url = remote_url.rpartition('@')\n        return remote_url\n    else:\n        return 'unknown_src_dir'\n\n\ndef install_environment(\n        prefix: Prefix,\n        version: str,\n        additional_dependencies: Sequence[str],\n) -> None:\n    helpers.assert_version_default('golang', version)\n    directory = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),\n    )\n\n    with clean_path_on_failure(directory):\n        remote = git.get_remote_url(prefix.prefix_dir)\n        repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote))\n\n        # Clone into the goenv we'll create\n        cmd = ('git', 'clone', '--recursive', '.', repo_src_dir)\n        helpers.run_setup_cmd(prefix, cmd)\n\n        if sys.platform == 'cygwin':  # pragma: no cover\n            _, gopath, _ = cmd_output('cygpath', '-w', directory)\n            gopath = gopath.strip()\n        else:\n            gopath = directory\n        env = dict(os.environ, GOPATH=gopath)\n        env.pop('GOBIN', None)\n        cmd_output_b('go', 'get', './...', cwd=repo_src_dir, env=env)\n        for dependency in additional_dependencies:\n            cmd_output_b('go', 'get', dependency, cwd=repo_src_dir, env=env)\n        # Same some disk space, we don't need these after installation\n        rmtree(prefix.path(directory, 'src'))\n        pkgdir = prefix.path(directory, 'pkg')\n        if os.path.exists(pkgdir):  # pragma: no cover (go<1.10)\n            rmtree(pkgdir)\n\n\ndef run_hook(\n        hook: Hook,\n        file_args: Sequence[str],\n        color: bool,\n) -> Tuple[int, bytes]:\n    with in_env(hook.prefix):\n        return helpers.run_xargs(hook, hook.cmd, file_args, color=color)\n", "path": "pre_commit/languages/golang.py"}]}