@@ -39,7 +39,7 @@ def test_is_script():
3939
4040def test_is_previous_pre_commit (tmpdir ):
4141 f = tmpdir .join ('foo' )
42- f .write (f'{ PRIOR_HASHES [0 ]} \n ' )
42+ f .write (f'{ PRIOR_HASHES [0 ]. decode () } \n ' )
4343 assert is_our_script (f .strpath )
4444
4545
@@ -390,6 +390,19 @@ def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store):
390390 NORMAL_PRE_COMMIT_RUN .assert_matches (output [len ('legacy hook\n ' ):])
391391
392392
393+ def test_install_with_existing_non_utf8_script (tmpdir , store ):
394+ cmd_output ('git' , 'init' , str (tmpdir ))
395+ tmpdir .join ('.git/hooks' ).ensure_dir ()
396+ tmpdir .join ('.git/hooks/pre-commit' ).write_binary (
397+ b'#!/usr/bin/env bash\n '
398+ b'# garbage: \xa0 \xef \x12 \xf2 \n '
399+ b'echo legacy hook\n ' ,
400+ )
401+
402+ with tmpdir .as_cwd ():
403+ assert install (C .CONFIG_FILE , store , hook_types = ['pre-commit' ]) == 0
404+
405+
393406FAIL_OLD_HOOK = re_assert .Matches (
394407 r'fail!\n'
395408 r'\[INFO\] Initializing environment for .+\.\n'
@@ -460,7 +473,7 @@ def test_replace_old_commit_script(tempdir_factory, store):
460473 # Install a script that looks like our old script
461474 pre_commit_contents = resource_text ('hook-tmpl' )
462475 new_contents = pre_commit_contents .replace (
463- CURRENT_HASH , PRIOR_HASHES [- 1 ],
476+ CURRENT_HASH . decode () , PRIOR_HASHES [- 1 ]. decode () ,
464477 )
465478
466479 os .makedirs (os .path .join (path , '.git/hooks' ), exist_ok = True )
0 commit comments