diff --git a/git/index/base.py b/git/index/base.py index 4f522b356..f3e0e2677 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -1665,6 +1665,7 @@ def diff( self.repo._empty_tree_hexsha, "--no-abbrev", "--full-index", + "--no-textconv", ] if not any(x in kwargs for x in ("find_renames", "no_renames", "M")): diff --git a/test/test_cli_safety.py b/test/test_cli_safety.py index ce6c4b42c..776a07dd0 100644 --- a/test/test_cli_safety.py +++ b/test/test_cli_safety.py @@ -9,7 +9,8 @@ from gitdb import IStream from gitdb.db import LooseObjectDB -from git import Git, Repo +from git import NULL_TREE, Git, Repo +from git.diff import NULL_TREE_SHA from git.exc import GitCommandError, UnsafeOptionError, UnsupportedOperation from test.lib.fixtures import fixture_repo, writable_fixture @@ -118,6 +119,16 @@ def test_managed_commands_disable_implicit_execution(plain_repo): assert execute.call_args.kwargs["env"]["GIT_NO_LAZY_FETCH"] == "1" +@pytest.mark.parametrize("other", [NULL_TREE, NULL_TREE_SHA]) +@pytest.mark.parametrize("create_patch", [False, True]) +def test_index_diff_against_empty_tree_disables_textconv(plain_repo, other, create_patch): + with patch.object(Git, "_call_process_safe", autospec=True, side_effect=Git._call_process_safe) as run: + assert plain_repo.index.diff(other, create_patch=create_patch) == [] + + assert run.call_args.args[1] == "diff" + assert "--no-textconv" in run.call_args.args[2:] + + def test_blame_and_archive_do_not_run_configured_commands(repo): marker = Path(repo.working_tree_dir) / "executed" commit = repo.head.commit