Skip to content

Commit cc3f297

Browse files
authored
Merge pull request pre-commit#572 from pre-commit/test_more_crlf
Add more tests for staged-files-only with crlf diffs
2 parents 454e0f2 + 51ed907 commit cc3f297

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/staged_files_only_test.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,59 @@ def test_non_utf8_conflicting_diff(foo_staged, cmd_runner):
312312
with io.open('foo', 'w') as foo_file:
313313
foo_file.write('')
314314
_test_foo_state(foo_staged, contents, 'AM', encoding='latin-1')
315+
316+
317+
@pytest.fixture
318+
def in_git_dir(tmpdir):
319+
with tmpdir.as_cwd():
320+
cmd_output('git', 'init', '.')
321+
yield tmpdir
322+
323+
324+
BEFORE = b'1\n2\n'
325+
AFTER = b'3\n4\n'
326+
327+
328+
def _crlf(b):
329+
return b.replace(b'\n', b'\r\n')
330+
331+
332+
def _write(b):
333+
with open('foo', 'wb') as f:
334+
f.write(b)
335+
336+
337+
def git_add():
338+
cmd_output('git', 'add', 'foo')
339+
340+
341+
def assert_no_diff():
342+
tree = cmd_output('git', 'write-tree')[1].strip()
343+
cmd_output('git', 'diff-index', tree, '--exit-code')
344+
345+
346+
BEFORE_AFTER = pytest.mark.parametrize(
347+
('before', 'after'),
348+
(
349+
(BEFORE, AFTER),
350+
(_crlf(BEFORE), _crlf(AFTER)),
351+
(_crlf(BEFORE), AFTER),
352+
(BEFORE, _crlf(AFTER)),
353+
),
354+
)
355+
356+
357+
@BEFORE_AFTER
358+
def test_default(in_git_dir, cmd_runner, before, after):
359+
_write(before)
360+
git_add()
361+
_write(after)
362+
with staged_files_only(cmd_runner):
363+
assert_no_diff()
364+
365+
366+
@BEFORE_AFTER
367+
@pytest.mark.parametrize('autocrlf', ('true', 'false', 'input'))
368+
def test_autocrlf_true(in_git_dir, cmd_runner, before, after, autocrlf):
369+
cmd_output('git', 'config', '--local', 'core.autocrlf', autocrlf)
370+
test_default(in_git_dir, cmd_runner, before, after)

0 commit comments

Comments
 (0)