diff --git a/CHANGES.rst b/CHANGES.rst index 4d2af1432..4eeaef028 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,7 @@ Added - New exit codes 2 for file not found, 3 for invalid command line arguments, 4 for missing dependencies and 123 for unknown failures. - Display exit code in parentheses after error message. +- Do not reformat renamed files. Fixed ----- diff --git a/src/darker/git.py b/src/darker/git.py index e89ca8636..20bd96259 100644 --- a/src/darker/git.py +++ b/src/darker/git.py @@ -145,6 +145,7 @@ def _git_diff_name_only( "diff", "--name-only", "--relative", + "--diff-filter=MA", rev1, # rev2 is inserted here if not WORKTREE "--", diff --git a/src/darker/tests/test_git.py b/src/darker/tests/test_git.py index 8b65ed855..6c9f84967 100644 --- a/src/darker/tests/test_git.py +++ b/src/darker/tests/test_git.py @@ -214,10 +214,12 @@ def test_get_missing_at_revision_worktree(git_repo): def test_git_diff_name_only(git_repo): - """``_git_diff_name_only()`` only returns paths of modified files""" + """``_git_diff_name_only()`` includes added/modified, skips renamed/moved files.""" git_repo.add({"a.py": "a", "b.py": "b", "c.py": "c"}, commit="Initial commit") first = git_repo.get_hash() git_repo.add({"a.py": "A", "b.dy": "B"}, commit="only a.py modified") + git_repo.rename("c.py", "x.py", commit="rename c.py to x.py") + second = git_repo.get_hash() result = git._git_diff_name_only( @@ -337,7 +339,6 @@ def test_git_get_modified_python_files(git_repo, modify_paths, paths, expect): _description="from master to worktree and index on branch", revrange="master..", expect={ - "del_master.py", "mod_master.py", "mod_both.py", "mod_branch.py", @@ -353,7 +354,6 @@ def test_git_get_modified_python_files(git_repo, modify_paths, paths, expect): ), revrange="master..HEAD", expect={ - "del_master.py", "mod_master.py", "mod_both.py", "mod_branch.py", @@ -363,7 +363,6 @@ def test_git_get_modified_python_files(git_repo, modify_paths, paths, expect): _description="from master to branch, excluding worktree and index", revrange="master..branch", expect={ - "del_master.py", "mod_master.py", "mod_both.py", "mod_branch.py", diff --git a/src/darker/tests/test_main_revision.py b/src/darker/tests/test_main_revision.py index 7d885f866..029f8b8c5 100644 --- a/src/darker/tests/test_main_revision.py +++ b/src/darker/tests/test_main_revision.py @@ -99,7 +99,9 @@ worktree_content=b"USERMOD=1\n", expect={"+1", "+1M0", "+2-1", "+2", "+2M1-0", "+2M1"}, ), - dict(revision="HEAD~2", worktree_content=b"ORIGINAL=1\n", expect={"+1", "+1M0"}), + # These are empty because git diff reports these are renamed files. + # We only care about added or modified files. See PR #454 + dict(revision="HEAD~2", worktree_content=b"ORIGINAL=1\n", expect=set()), dict( revision="HEAD~2", worktree_content=b"MODIFIED=1\n",