|
10 | 10 | import re_assert |
11 | 11 |
|
12 | 12 | import pre_commit.constants as C |
| 13 | +from pre_commit import git |
13 | 14 | from pre_commit.clientlib import CONFIG_SCHEMA |
14 | 15 | from pre_commit.clientlib import load_manifest |
15 | 16 | from pre_commit.envcontext import envcontext |
@@ -346,6 +347,59 @@ def test_golang_hook_still_works_when_gobin_is_set(tempdir_factory, store): |
346 | 347 | assert os.listdir(gobin_dir) == [] |
347 | 348 |
|
348 | 349 |
|
| 350 | +def test_golang_with_recursive_submodule(tmpdir, tempdir_factory, store): |
| 351 | + sub_go = '''\ |
| 352 | +package sub |
| 353 | +
|
| 354 | +import "fmt" |
| 355 | +
|
| 356 | +func Func() { |
| 357 | + fmt.Println("hello hello world") |
| 358 | +} |
| 359 | +''' |
| 360 | + sub = tmpdir.join('sub').ensure_dir() |
| 361 | + sub.join('sub.go').write(sub_go) |
| 362 | + cmd_output('git', '-C', str(sub), 'init', '.') |
| 363 | + cmd_output('git', '-C', str(sub), 'add', '.') |
| 364 | + git.commit(str(sub)) |
| 365 | + |
| 366 | + pre_commit_hooks = '''\ |
| 367 | +- id: example |
| 368 | + name: example |
| 369 | + entry: example |
| 370 | + language: golang |
| 371 | + verbose: true |
| 372 | +''' |
| 373 | + go_mod = '''\ |
| 374 | +module github.com/asottile/example |
| 375 | +
|
| 376 | +go 1.14 |
| 377 | +''' |
| 378 | + main_go = '''\ |
| 379 | +package main |
| 380 | +
|
| 381 | +import "github.com/asottile/example/sub" |
| 382 | +
|
| 383 | +func main() { |
| 384 | + sub.Func() |
| 385 | +} |
| 386 | +''' |
| 387 | + repo = tmpdir.join('repo').ensure_dir() |
| 388 | + repo.join('.pre-commit-hooks.yaml').write(pre_commit_hooks) |
| 389 | + repo.join('go.mod').write(go_mod) |
| 390 | + repo.join('main.go').write(main_go) |
| 391 | + cmd_output('git', '-C', str(repo), 'init', '.') |
| 392 | + cmd_output('git', '-C', str(repo), 'add', '.') |
| 393 | + cmd_output('git', '-C', str(repo), 'submodule', 'add', str(sub), 'sub') |
| 394 | + git.commit(str(repo)) |
| 395 | + |
| 396 | + config = make_config_from_repo(str(repo)) |
| 397 | + hook = _get_hook(config, store, 'example') |
| 398 | + ret, out = _hook_run(hook, (), color=False) |
| 399 | + assert ret == 0 |
| 400 | + assert _norm_out(out) == b'hello hello world\n' |
| 401 | + |
| 402 | + |
349 | 403 | def test_rust_hook(tempdir_factory, store): |
350 | 404 | _test_hook_repo( |
351 | 405 | tempdir_factory, store, 'rust_hooks_repo', |
|
0 commit comments