Don't fail if GPG signing is configured by default. All references. · precommit/pre-commit@28c97a9 · GitHub
Skip to content

Commit 28c97a9

Browse files
committed
Don't fail if GPG signing is configured by default. All references.
1 parent 7afb294 commit 28c97a9

10 files changed

Lines changed: 60 additions & 50 deletions

testing/fixtures.py

Lines changed: 6 additions & 17 deletions

testing/util.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,18 @@ def cwd(path):
133133
yield
134134
finally:
135135
os.chdir(original_cwd)
136+
137+
138+
def git_commit(msg, *_args, **kwargs):
139+
args = ['git']
140+
config = kwargs.pop('config', None)
141+
if config is not None:
142+
args.extend(['-C', config])
143+
args.append('commit')
144+
if msg is not None:
145+
args.extend(['-m', msg])
146+
if '--allow-empty' not in _args:
147+
args.append('--allow-empty')
148+
if '--no-gpg-sign' not in _args:
149+
args.append('--no-gpg-sign')
150+
return cmd_output(*(tuple(args) + tuple(_args)), **kwargs)

tests/commands/autoupdate_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from testing.fixtures import make_repo
2222
from testing.fixtures import write_config
2323
from testing.util import get_resource_path
24+
from testing.util import git_commit
2425

2526

2627
@pytest.fixture
@@ -59,11 +60,11 @@ def test_autoupdate_old_revision_broken(tempdir_factory, in_tmpdir, store):
5960
config = make_config_from_repo(path, check=False)
6061

6162
cmd_output('git', 'mv', C.MANIFEST_FILE, 'nope.yaml', cwd=path)
62-
cmd_output('git', 'commit', '-m', 'simulate old repo', cwd=path)
63+
git_commit('simulate old repo', cwd=path)
6364
# Assume this is the revision the user's old repository was at
6465
rev = git.head_rev(path)
6566
cmd_output('git', 'mv', 'nope.yaml', C.MANIFEST_FILE, cwd=path)
66-
cmd_output('git', 'commit', '-m', 'move hooks file', cwd=path)
67+
git_commit('move hooks file', cwd=path)
6768
update_rev = git.head_rev(path)
6869

6970
config['rev'] = rev
@@ -84,7 +85,7 @@ def out_of_date_repo(tempdir_factory):
8485
original_rev = git.head_rev(path)
8586

8687
# Make a commit
87-
cmd_output('git', 'commit', '--allow-empty', '-m', 'foo', cwd=path)
88+
git_commit('foo', cwd=path)
8889
head_rev = git.head_rev(path)
8990

9091
yield auto_namedtuple(
@@ -239,7 +240,7 @@ def test_autoupdate_tagged_repo(tagged_repo, in_tmpdir, store):
239240

240241
@pytest.fixture
241242
def tagged_repo_with_more_commits(tagged_repo):
242-
cmd_output('git', 'commit', '--allow-empty', '-mfoo', cwd=tagged_repo.path)
243+
git_commit('foo', cwd=tagged_repo.path)
243244
yield tagged_repo
244245

245246

@@ -263,7 +264,7 @@ def test_autoupdate_latest_no_config(out_of_date_repo, in_tmpdir, store):
263264
write_config('.', config)
264265

265266
cmd_output('git', '-C', out_of_date_repo.path, 'rm', '-r', ':/')
266-
cmd_output('git', '-C', out_of_date_repo.path, 'commit', '-m', 'rm')
267+
git_commit('rm', config=out_of_date_repo.path)
267268

268269
ret = autoupdate(C.CONFIG_FILE, store, tags_only=False)
269270
assert ret == 1
@@ -281,7 +282,7 @@ def hook_disappearing_repo(tempdir_factory):
281282
os.path.join(path, C.MANIFEST_FILE),
282283
)
283284
cmd_output('git', 'add', '.', cwd=path)
284-
cmd_output('git', 'commit', '-m', 'Remove foo', cwd=path)
285+
git_commit('Remove foo', cwd=path)
285286

286287
yield auto_namedtuple(path=path, original_rev=original_rev)
287288

tests/commands/install_uninstall_test.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from testing.fixtures import remove_config_from_repo
2929
from testing.util import cmd_output_mocked_pre_commit_home
3030
from testing.util import cwd
31+
from testing.util import git_commit
3132
from testing.util import xfailif_no_symlink
3233

3334

@@ -109,7 +110,7 @@ def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs):
109110
open(touch_file, 'a').close()
110111
cmd_output('git', 'add', touch_file)
111112
return cmd_output_mocked_pre_commit_home(
112-
'git', 'commit', '-am', commit_msg, '--allow-empty',
113+
'git', 'commit', '-am', commit_msg, '--allow-empty', '--no-gpg-sign',
113114
# git commit puts pre-commit to stderr
114115
stderr=subprocess.STDOUT,
115116
retcode=None,
@@ -151,7 +152,7 @@ def test_install_pre_commit_and_run_custom_path(tempdir_factory, store):
151152
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
152153
with cwd(path):
153154
cmd_output('git', 'mv', C.CONFIG_FILE, 'custom-config.yaml')
154-
cmd_output('git', 'commit', '-m', 'move pre-commit config')
155+
git_commit('move pre-commit config')
155156
assert install('custom-config.yaml', store) == 0
156157

157158
ret, output = _get_commit_output(tempdir_factory)
@@ -163,7 +164,7 @@ def test_install_in_submodule_and_run(tempdir_factory, store):
163164
src_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
164165
parent_path = git_dir(tempdir_factory)
165166
cmd_output('git', 'submodule', 'add', src_path, 'sub', cwd=parent_path)
166-
cmd_output('git', 'commit', '-m', 'foo', cwd=parent_path)
167+
git_commit('foo', cwd=parent_path)
167168

168169
sub_pth = os.path.join(parent_path, 'sub')
169170
with cwd(sub_pth):
@@ -193,7 +194,7 @@ def test_commit_am(tempdir_factory, store):
193194
# Make an unstaged change
194195
open('unstaged', 'w').close()
195196
cmd_output('git', 'add', '.')
196-
cmd_output('git', 'commit', '-m', 'foo')
197+
git_commit('foo')
197198
with io.open('unstaged', 'w') as foo_file:
198199
foo_file.write('Oh hai')
199200

@@ -208,12 +209,12 @@ def test_unicode_merge_commit_message(tempdir_factory, store):
208209
with cwd(path):
209210
assert install(C.CONFIG_FILE, store) == 0
210211
cmd_output('git', 'checkout', 'master', '-b', 'foo')
211-
cmd_output('git', 'commit', '--allow-empty', '-n', '-m', 'branch2')
212+
git_commit('branch2', '-n')
212213
cmd_output('git', 'checkout', 'master')
213214
cmd_output('git', 'merge', 'foo', '--no-ff', '--no-commit', '-m', '☃')
214215
# Used to crash
215216
cmd_output_mocked_pre_commit_home(
216-
'git', 'commit', '--no-edit',
217+
'git', 'commit', '--no-edit', '--no-gpg-sign',
217218
tempdir_factory=tempdir_factory,
218219
)
219220

@@ -246,8 +247,8 @@ def test_environment_not_sourced(tempdir_factory, store):
246247

247248
# Use a specific homedir to ignore --user installs
248249
homedir = tempdir_factory.get()
249-
ret, stdout, stderr = cmd_output(
250-
'git', 'commit', '--allow-empty', '-m', 'foo',
250+
ret, stdout, stderr = git_commit(
251+
'foo',
251252
env={
252253
'HOME': homedir,
253254
'PATH': _path_without_us(),

tests/commands/run_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def test_stdout_write_bug_py26(repo_with_failing_hook, store, tempdir_factory):
479479

480480
# Have to use subprocess because pytest monkeypatches sys.stdout
481481
_, stdout, _ = cmd_output_mocked_pre_commit_home(
482-
'git', 'commit', '-m', 'Commit!',
482+
'git', 'commit', '-m', 'Commit!', '--no-gpg-sign',
483483
# git commit puts pre-commit to stderr
484484
stderr=subprocess.STDOUT,
485485
retcode=None,
@@ -508,7 +508,7 @@ def test_lots_of_files(store, tempdir_factory):
508508
install(C.CONFIG_FILE, store)
509509

510510
cmd_output_mocked_pre_commit_home(
511-
'git', 'commit', '-m', 'Commit!',
511+
'git', 'commit', '-m', 'Commit!', '--no-gpg-sign',
512512
# git commit puts pre-commit to stderr
513513
stderr=subprocess.STDOUT,
514514
tempdir_factory=tempdir_factory,

tests/conftest.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from testing.fixtures import make_consuming_repo
2020
from testing.fixtures import write_config
2121
from testing.util import cwd
22+
from testing.util import git_commit
2223

2324

2425
@pytest.fixture(autouse=True)
@@ -79,15 +80,15 @@ def _make_conflict():
7980
with io.open('foo_only_file', 'w') as foo_only_file:
8081
foo_only_file.write('foo')
8182
cmd_output('git', 'add', 'foo_only_file')
82-
cmd_output('git', 'commit', '-m', 'conflict_file')
83+
git_commit('conflict_file')
8384
cmd_output('git', 'checkout', 'origin/master', '-b', 'bar')
8485
with io.open('conflict_file', 'w') as conflict_file:
8586
conflict_file.write('harp\nddrp\n')
8687
cmd_output('git', 'add', 'conflict_file')
8788
with io.open('bar_only_file', 'w') as bar_only_file:
8889
bar_only_file.write('bar')
8990
cmd_output('git', 'add', 'bar_only_file')
90-
cmd_output('git', 'commit', '-m', 'conflict_file')
91+
git_commit('conflict_file')
9192
cmd_output('git', 'merge', 'foo', retcode=None)
9293

9394

@@ -96,7 +97,7 @@ def in_merge_conflict(tempdir_factory):
9697
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
9798
open(os.path.join(path, 'dummy'), 'a').close()
9899
cmd_output('git', 'add', 'dummy', cwd=path)
99-
cmd_output('git', 'commit', '-m', 'Add config.', cwd=path)
100+
git_commit('Add config.', cwd=path)
100101

101102
conflict_path = tempdir_factory.get()
102103
cmd_output('git', 'clone', path, conflict_path)
@@ -109,7 +110,7 @@ def in_merge_conflict(tempdir_factory):
109110
def in_conflicting_submodule(tempdir_factory):
110111
git_dir_1 = git_dir(tempdir_factory)
111112
git_dir_2 = git_dir(tempdir_factory)
112-
cmd_output('git', 'commit', '--allow-empty', '-minit!', cwd=git_dir_2)
113+
git_commit('init!', cwd=git_dir_2)
113114
cmd_output('git', 'submodule', 'add', git_dir_2, 'sub', cwd=git_dir_1)
114115
with cwd(os.path.join(git_dir_1, 'sub')):
115116
_make_conflict()
@@ -135,7 +136,7 @@ def commit_msg_repo(tempdir_factory):
135136
write_config(path, config)
136137
with cwd(path):
137138
cmd_output('git', 'add', '.')
138-
cmd_output('git', 'commit', '-m', 'add hooks')
139+
git_commit('add hooks')
139140
yield path
140141

141142

tests/git_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pre_commit import git
1010
from pre_commit.error_handler import FatalError
1111
from pre_commit.util import cmd_output
12+
from testing.util import git_commit
1213

1314

1415
def test_get_root_at_root(in_git_dir):
@@ -104,11 +105,11 @@ def test_parse_merge_msg_for_conflicts(input, expected_output):
104105

105106

106107
def test_get_changed_files(in_git_dir):
107-
cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit')
108+
git_commit('initial commit')
108109
in_git_dir.join('a.txt').ensure()
109110
in_git_dir.join('b.txt').ensure()
110111
cmd_output('git', 'add', '.')
111-
cmd_output('git', 'commit', '-m', 'add some files')
112+
git_commit('add some files')
112113
files = git.get_changed_files('HEAD', 'HEAD^')
113114
assert files == ['a.txt', 'b.txt']
114115

@@ -132,10 +133,10 @@ def test_zsplit(s, expected):
132133

133134
@pytest.fixture
134135
def non_ascii_repo(in_git_dir):
135-
cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit')
136+
git_commit('initial commit')
136137
in_git_dir.join('интервью').ensure()
137138
cmd_output('git', 'add', '.')
138-
cmd_output('git', 'commit', '--allow-empty', '-m', 'initial commit')
139+
git_commit('initial commit')
139140
yield in_git_dir
140141

141142

tests/make_archives_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pre_commit import make_archives
99
from pre_commit.util import cmd_output
1010
from testing.fixtures import git_dir
11+
from testing.util import git_commit
1112

1213

1314
def test_make_archive(tempdir_factory):
@@ -16,13 +17,13 @@ def test_make_archive(tempdir_factory):
1617
# Add a files to the git directory
1718
open(os.path.join(git_path, 'foo'), 'a').close()
1819
cmd_output('git', 'add', '.', cwd=git_path)
19-
cmd_output('git', 'commit', '-m', 'foo', cwd=git_path)
20+
git_commit('foo', cwd=git_path)
2021
# We'll use this rev
2122
head_rev = git.head_rev(git_path)
2223
# And check that this file doesn't exist
2324
open(os.path.join(git_path, 'bar'), 'a').close()
2425
cmd_output('git', 'add', '.', cwd=git_path)
25-
cmd_output('git', 'commit', '-m', 'bar', cwd=git_path)
26+
git_commit('bar', cwd=git_path)
2627

2728
# Do the thing
2829
archive_path = make_archives.make_archive(

tests/staged_files_only_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from testing.fixtures import git_dir
1616
from testing.util import cwd
1717
from testing.util import get_resource_path
18+
from testing.util import git_commit
1819

1920

2021
FOO_CONTENTS = '\n'.join(('1', '2', '3', '4', '5', '6', '7', '8', ''))
@@ -186,9 +187,9 @@ def test_img_conflict(img_staged, patch_dir):
186187
def submodule_with_commits(tempdir_factory):
187188
path = git_dir(tempdir_factory)
188189
with cwd(path):
189-
cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
190+
git_commit('foo')
190191
rev1 = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
191-
cmd_output('git', 'commit', '--allow-empty', '-m', 'bar')
192+
git_commit('bar')
192193
rev2 = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
193194
yield auto_namedtuple(path=path, rev1=rev1, rev2=rev2)
194195

@@ -331,7 +332,7 @@ def test_autocrlf_commited_crlf(in_git_dir, patch_dir):
331332
cmd_output('git', 'config', '--local', 'core.autocrlf', 'false')
332333
_write(b'1\r\n2\r\n')
333334
cmd_output('git', 'add', 'foo')
334-
cmd_output('git', 'commit', '-m', 'Check in crlf')
335+
git_commit('Check in crlf')
335336

336337
cmd_output('git', 'config', '--local', 'core.autocrlf', 'true')
337338
_write(b'1\r\n2\r\n\r\n\r\n\r\n')

tests/store_test.py

Lines changed: 3 additions & 3 deletions

0 commit comments

Comments
 (0)