Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d6efe1

Browse files
authored
Merge pull request #680 from pre-commit/local_golang_repos
Fix broken local golang repos
2 parents 0628df5 + 4069006 commit 4d6efe1

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

pre_commit/store.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ def clone_strategy(directory):
156156
def make_local(self, deps):
157157
def make_local_strategy(directory):
158158
copy_tree_to_path(resource_filename('empty_template'), directory)
159+
160+
env = no_git_env()
161+
name, email = 'pre-commit', '[email protected]'
162+
env['GIT_AUTHOR_NAME'] = env['GIT_COMMITTER_NAME'] = name
163+
env['GIT_AUTHOR_EMAIL'] = env['GIT_COMMITTER_EMAIL'] = email
164+
165+
# initialize the git repository so it looks more like cloned repos
166+
def _git_cmd(*args):
167+
cmd_output('git', '-C', directory, *args, env=env)
168+
169+
_git_cmd('init', '.')
170+
_git_cmd('config', 'remote.origin.url', '<<unknown>>')
171+
_git_cmd('add', '.')
172+
_git_cmd('commit', '--no-edit', '--no-gpg-sign', '-n', '-minit')
173+
159174
return self._new_repo(
160175
'local:{}'.format(','.join(sorted(deps))), C.LOCAL_REPO_VERSION,
161176
make_local_strategy,

tests/repository_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,24 @@ def test_additional_golang_dependencies_installed(
541541
assert 'hello' in binaries
542542

543543

544+
def test_local_golang_additional_dependencies(store):
545+
config = {
546+
'repo': 'local',
547+
'hooks': [{
548+
'id': 'hello',
549+
'name': 'hello',
550+
'entry': 'hello',
551+
'language': 'golang',
552+
'additional_dependencies': ['github.com/golang/example/hello'],
553+
}],
554+
}
555+
repo = Repository.create(config, store)
556+
(_, hook), = repo.hooks
557+
ret = repo.run_hook(hook, ('filename',))
558+
assert ret[0] == 0
559+
assert _norm_out(ret[1]) == b"Hello, Go examples!\n"
560+
561+
544562
def test_reinstall(tempdir_factory, store, log_info_mock):
545563
path = make_repo(tempdir_factory, 'python_hooks_repo')
546564
config = make_config_from_repo(path)

0 commit comments

Comments
 (0)