@@ -280,3 +280,28 @@ def test_stage_non_utf8_changes(foo_staged, cmd_runner):
280280 with staged_files_only (cmd_runner ):
281281 _test_foo_state (foo_staged )
282282 _test_foo_state (foo_staged , contents , 'AM' , encoding = 'latin-1' )
283+
284+
285+ def test_non_utf8_conflicting_diff (foo_staged , cmd_runner ):
286+ """Regression test for #397"""
287+ # The trailing whitespace is important here, this triggers git to produce
288+ # an error message which looks like:
289+ #
290+ # ...patch1471530032:14: trailing whitespace.
291+ # [[unprintable character]][[space character]]
292+ # error: patch failed: foo:1
293+ # error: foo: patch does not apply
294+ #
295+ # Previously, the error message (though discarded immediately) was being
296+ # decoded with the UTF-8 codec (causing a crash)
297+ contents = 'ú \n '
298+ with io .open ('foo' , 'w' , encoding = 'latin-1' ) as foo_file :
299+ foo_file .write (contents )
300+
301+ _test_foo_state (foo_staged , contents , 'AM' , encoding = 'latin-1' )
302+ with staged_files_only (cmd_runner ):
303+ _test_foo_state (foo_staged )
304+ # Create a conflicting diff that will need to be rolled back
305+ with io .open ('foo' , 'w' ) as foo_file :
306+ foo_file .write ('' )
307+ _test_foo_state (foo_staged , contents , 'AM' , encoding = 'latin-1' )
0 commit comments