2828from testing .fixtures import remove_config_from_repo
2929from testing .util import cmd_output_mocked_pre_commit_home
3030from testing .util import cwd
31+ from testing .util import git_commit
3132from testing .util import xfailif_no_symlink
3233
3334
@@ -105,11 +106,10 @@ def test_uninstall(in_git_dir, store):
105106
106107
107108def _get_commit_output (tempdir_factory , touch_file = 'foo' , ** kwargs ):
108- commit_msg = kwargs .pop ('commit_msg' , 'Commit!' )
109109 open (touch_file , 'a' ).close ()
110110 cmd_output ('git' , 'add' , touch_file )
111- return cmd_output_mocked_pre_commit_home (
112- 'git' , 'commit' , '-am' , commit_msg , '--allow-empty' ,
111+ return git_commit (
112+ fn = cmd_output_mocked_pre_commit_home ,
113113 # git commit puts pre-commit to stderr
114114 stderr = subprocess .STDOUT ,
115115 retcode = None ,
@@ -131,7 +131,7 @@ def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs):
131131NORMAL_PRE_COMMIT_RUN = re .compile (
132132 r'^\[INFO\] Initializing environment for .+\.\r?\n'
133133 r'Bash hook\.+Passed\r?\n'
134- r'\[master [a-f0-9]{7}\] Commit !\r?\n' +
134+ r'\[master [a-f0-9]{7}\] commit !\r?\n' +
135135 FILES_CHANGED +
136136 r' create mode 100644 foo\r?\n$' ,
137137)
@@ -151,7 +151,7 @@ def test_install_pre_commit_and_run_custom_path(tempdir_factory, store):
151151 path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
152152 with cwd (path ):
153153 cmd_output ('git' , 'mv' , C .CONFIG_FILE , 'custom-config.yaml' )
154- cmd_output ( 'git' , 'commit' , '-m' , 'move pre-commit config' )
154+ git_commit ( cwd = path )
155155 assert install ('custom-config.yaml' , store ) == 0
156156
157157 ret , output = _get_commit_output (tempdir_factory )
@@ -163,7 +163,7 @@ def test_install_in_submodule_and_run(tempdir_factory, store):
163163 src_path = make_consuming_repo (tempdir_factory , 'script_hooks_repo' )
164164 parent_path = git_dir (tempdir_factory )
165165 cmd_output ('git' , 'submodule' , 'add' , src_path , 'sub' , cwd = parent_path )
166- cmd_output ( 'git' , 'commit' , '-m' , 'foo' , cwd = parent_path )
166+ git_commit ( cwd = parent_path )
167167
168168 sub_pth = os .path .join (parent_path , 'sub' )
169169 with cwd (sub_pth ):
@@ -193,7 +193,7 @@ def test_commit_am(tempdir_factory, store):
193193 # Make an unstaged change
194194 open ('unstaged' , 'w' ).close ()
195195 cmd_output ('git' , 'add' , '.' )
196- cmd_output ( 'git' , 'commit' , '-m' , 'foo' )
196+ git_commit ( cwd = path )
197197 with io .open ('unstaged' , 'w' ) as foo_file :
198198 foo_file .write ('Oh hai' )
199199
@@ -208,12 +208,14 @@ def test_unicode_merge_commit_message(tempdir_factory, store):
208208 with cwd (path ):
209209 assert install (C .CONFIG_FILE , store ) == 0
210210 cmd_output ('git' , 'checkout' , 'master' , '-b' , 'foo' )
211- cmd_output ( 'git' , 'commit' , '--allow-empty' , '- n' , '-m' , 'branch2' )
211+ git_commit ( '- n' , cwd = path )
212212 cmd_output ('git' , 'checkout' , 'master' )
213213 cmd_output ('git' , 'merge' , 'foo' , '--no-ff' , '--no-commit' , '-m' , '☃' )
214214 # Used to crash
215- cmd_output_mocked_pre_commit_home (
216- 'git' , 'commit' , '--no-edit' ,
215+ git_commit (
216+ '--no-edit' ,
217+ msg = None ,
218+ fn = cmd_output_mocked_pre_commit_home ,
217219 tempdir_factory = tempdir_factory ,
218220 )
219221
@@ -246,8 +248,7 @@ def test_environment_not_sourced(tempdir_factory, store):
246248
247249 # Use a specific homedir to ignore --user installs
248250 homedir = tempdir_factory .get ()
249- ret , stdout , stderr = cmd_output (
250- 'git' , 'commit' , '--allow-empty' , '-m' , 'foo' ,
251+ ret , stdout , stderr = git_commit (
251252 env = {
252253 'HOME' : homedir ,
253254 'PATH' : _path_without_us (),
@@ -290,7 +291,7 @@ def test_failing_hooks_returns_nonzero(tempdir_factory, store):
290291
291292EXISTING_COMMIT_RUN = re .compile (
292293 r'^legacy hook\r?\n'
293- r'\[master [a-f0-9]{7}\] Commit !\r?\n' +
294+ r'\[master [a-f0-9]{7}\] commit !\r?\n' +
294295 FILES_CHANGED +
295296 r' create mode 100644 baz\r?\n$' ,
296297)
@@ -433,7 +434,7 @@ def test_uninstall_doesnt_remove_not_our_hooks(in_git_dir):
433434
434435PRE_INSTALLED = re .compile (
435436 r'Bash hook\.+Passed\r?\n'
436- r'\[master [a-f0-9]{7}\] Commit !\r?\n' +
437+ r'\[master [a-f0-9]{7}\] commit !\r?\n' +
437438 FILES_CHANGED +
438439 r' create mode 100644 foo\r?\n$' ,
439440)
@@ -545,7 +546,7 @@ def test_pre_push_force_push_without_fetch(tempdir_factory, store):
545546
546547 with cwd (path2 ):
547548 install (C .CONFIG_FILE , store , hook_type = 'pre-push' )
548- assert _get_commit_output (tempdir_factory , commit_msg = 'force!' )[0 ] == 0
549+ assert _get_commit_output (tempdir_factory , msg = 'force!' )[0 ] == 0
549550
550551 retc , output = _get_push_output (tempdir_factory , opts = ('--force' ,))
551552 assert retc == 0
@@ -624,7 +625,7 @@ def test_commit_msg_integration_passing(
624625):
625626 install (C .CONFIG_FILE , store , hook_type = 'commit-msg' )
626627 msg = 'Hi\n Signed off by: me, lol'
627- retc , out = _get_commit_output (tempdir_factory , commit_msg = msg )
628+ retc , out = _get_commit_output (tempdir_factory , msg = msg )
628629 assert retc == 0
629630 first_line = out .splitlines ()[0 ]
630631 assert first_line .startswith ('Must have "Signed off by:"...' )
@@ -646,7 +647,7 @@ def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
646647 install (C .CONFIG_FILE , store , hook_type = 'commit-msg' )
647648
648649 msg = 'Hi\n Signed off by: asottile'
649- retc , out = _get_commit_output (tempdir_factory , commit_msg = msg )
650+ retc , out = _get_commit_output (tempdir_factory , msg = msg )
650651 assert retc == 0
651652 first_line , second_line = out .splitlines ()[:2 ]
652653 assert first_line == 'legacy'
0 commit comments