mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1789 from paulhfischer/recursive_golang
added recursive repository support for golang
This commit is contained in:
commit
2dac92cc8c
2 changed files with 56 additions and 1 deletions
|
|
@ -69,7 +69,8 @@ def install_environment(
|
||||||
repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote))
|
repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote))
|
||||||
|
|
||||||
# Clone into the goenv we'll create
|
# 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
|
if sys.platform == 'cygwin': # pragma: no cover
|
||||||
_, gopath, _ = cmd_output('cygpath', '-w', directory)
|
_, gopath, _ = cmd_output('cygpath', '-w', directory)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import pytest
|
||||||
import re_assert
|
import re_assert
|
||||||
|
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
|
from pre_commit import git
|
||||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||||
from pre_commit.clientlib import load_manifest
|
from pre_commit.clientlib import load_manifest
|
||||||
from pre_commit.envcontext import envcontext
|
from pre_commit.envcontext import envcontext
|
||||||
|
|
@ -346,6 +347,59 @@ def test_golang_hook_still_works_when_gobin_is_set(tempdir_factory, store):
|
||||||
assert os.listdir(gobin_dir) == []
|
assert os.listdir(gobin_dir) == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_golang_with_recursive_submodule(tmpdir, tempdir_factory, store):
|
||||||
|
sub_go = '''\
|
||||||
|
package sub
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func Func() {
|
||||||
|
fmt.Println("hello hello world")
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
sub = tmpdir.join('sub').ensure_dir()
|
||||||
|
sub.join('sub.go').write(sub_go)
|
||||||
|
cmd_output('git', '-C', str(sub), 'init', '.')
|
||||||
|
cmd_output('git', '-C', str(sub), 'add', '.')
|
||||||
|
git.commit(str(sub))
|
||||||
|
|
||||||
|
pre_commit_hooks = '''\
|
||||||
|
- id: example
|
||||||
|
name: example
|
||||||
|
entry: example
|
||||||
|
language: golang
|
||||||
|
verbose: true
|
||||||
|
'''
|
||||||
|
go_mod = '''\
|
||||||
|
module github.com/asottile/example
|
||||||
|
|
||||||
|
go 1.14
|
||||||
|
'''
|
||||||
|
main_go = '''\
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/asottile/example/sub"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
sub.Func()
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
repo = tmpdir.join('repo').ensure_dir()
|
||||||
|
repo.join('.pre-commit-hooks.yaml').write(pre_commit_hooks)
|
||||||
|
repo.join('go.mod').write(go_mod)
|
||||||
|
repo.join('main.go').write(main_go)
|
||||||
|
cmd_output('git', '-C', str(repo), 'init', '.')
|
||||||
|
cmd_output('git', '-C', str(repo), 'add', '.')
|
||||||
|
cmd_output('git', '-C', str(repo), 'submodule', 'add', str(sub), 'sub')
|
||||||
|
git.commit(str(repo))
|
||||||
|
|
||||||
|
config = make_config_from_repo(str(repo))
|
||||||
|
hook = _get_hook(config, store, 'example')
|
||||||
|
ret, out = _hook_run(hook, (), color=False)
|
||||||
|
assert ret == 0
|
||||||
|
assert _norm_out(out) == b'hello hello world\n'
|
||||||
|
|
||||||
|
|
||||||
def test_rust_hook(tempdir_factory, store):
|
def test_rust_hook(tempdir_factory, store):
|
||||||
_test_hook_repo(
|
_test_hook_repo(
|
||||||
tempdir_factory, store, 'rust_hooks_repo',
|
tempdir_factory, store, 'rust_hooks_repo',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue