# Buggy code
def install_environment(
    prefix: Prefix,
    version: str,
    additional_dependencies: Sequence[str],
) -> None:
    helpers.assert_version_default("golang", version)
    directory = prefix.path(
        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),
    )

    with clean_path_on_failure(directory):
        remote = git.get_remote_url(prefix.prefix_dir)
        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))

        if sys.platform == "cygwin":  # pragma: no cover
            _, gopath, _ = cmd_output("cygpath", "-w", directory)
            gopath = gopath.strip()
        else:
            gopath = directory
        env = dict(os.environ, GOPATH=gopath)
        env.pop("GOBIN", None)
        cmd_output_b("go", "get", "./...", cwd=repo_src_dir, env=env)
        for dependency in additional_dependencies:
            cmd_output_b("go", "get", dependency, cwd=repo_src_dir, env=env)
        # Same some disk space, we don't need these after installation
        rmtree(prefix.path(directory, "src"))
        pkgdir = prefix.path(directory, "pkg")
        if os.path.exists(pkgdir):  # pragma: no cover (go<1.10)
            rmtree(pkgdir)


# Traceback (pre_commit.util.CalledProcessError)
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

# Fixed code
def install_environment(
    prefix: Prefix,
    version: str,
    additional_dependencies: Sequence[str],
) -> None:
    helpers.assert_version_default("golang", version)
    directory = prefix.path(
        helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT),
    )

    with clean_path_on_failure(directory):
        remote = git.get_remote_url(prefix.prefix_dir)
        repo_src_dir = os.path.join(directory, "src", guess_go_dir(remote))

        # Clone into the goenv we'll create
        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)
            gopath = gopath.strip()
        else:
            gopath = directory
        env = dict(os.environ, GOPATH=gopath)
        env.pop("GOBIN", None)
        cmd_output_b("go", "get", "./...", cwd=repo_src_dir, env=env)
        for dependency in additional_dependencies:
            cmd_output_b("go", "get", dependency, cwd=repo_src_dir, env=env)
        # Same some disk space, we don't need these after installation
        rmtree(prefix.path(directory, "src"))
        pkgdir = prefix.path(directory, "pkg")
        if os.path.exists(pkgdir):  # pragma: no cover (go<1.10)
            rmtree(pkgdir)