Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out unmodified files from list of changed files #545

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/darker/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def _git_diff_name_only(
"diff",
"--name-only",
"--relative",
"--diff-filter=MA",
rev1,
# rev2 is inserted here if not WORKTREE
"--",
Expand Down
Empty file added src/darker/tests/conftest.py
Empty file.
8 changes: 4 additions & 4 deletions src/darker/tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ 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()`` only returns paths of modified files and ignores
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(
Expand Down Expand Up @@ -266,7 +269,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",
Expand All @@ -282,7 +284,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",
Expand All @@ -292,7 +293,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",
Expand Down
4 changes: 3 additions & 1 deletion src/darker/tests/test_main_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down