Skip to content

Commit

Permalink
Merge pull request #634 from JulienBortolussiAda/raise_empty_diff_error
Browse files Browse the repository at this point in the history
e3.diff.patch raise EmptyDiffError when doing nothing
  • Loading branch information
JulienBortolussiAda authored Oct 3, 2023
2 parents ffadad2 + 19309af commit 1c03c2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/e3/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@


class DiffError(e3.error.E3Error):
"""Error returned when the patch command fails."""

pass


class EmptyDiffError(DiffError):
"""Error returned when the patch is empty.
These situation can occur when all the patched files are discarded.
"""

pass


Expand Down Expand Up @@ -268,6 +279,6 @@ def process_git_patch() -> int:
files_to_patch = process_regular_patch()

if files_to_patch == 0:
raise DiffError(origin="patch", message="No file to patch")
raise EmptyDiffError(origin="patch", message="No file to patch")

apply_patch(filtered_patch)
6 changes: 3 additions & 3 deletions tests/tests_e3/diff/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_patch_ignore_all(caplog):

e3.fs.cp(file_to_patch, current_dir)
e3.fs.cp(file_patch2, current_dir)
with pytest.raises(e3.diff.DiffError):
with pytest.raises(e3.diff.EmptyDiffError):
e3.diff.patch("patch2.txt", current_dir, discarded_files=lambda x: True)


Expand Down Expand Up @@ -144,7 +144,7 @@ def test_patch_git_format_ignore():
assert "That's nice it's working !" in content

e3.fs.cp(file_to_patch, cwd)
with pytest.raises(e3.diff.DiffError):
with pytest.raises(e3.diff.EmptyDiffError):
e3.diff.patch("git_diff.patch", cwd, discarded_files=["git_file.txt"])

with open(os.path.join(cwd, "git_file.txt")) as fd:
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_patch_git_with_headers():

e3.fs.rm("file1")
e3.fs.rm("file2")
with pytest.raises(e3.diff.DiffError):
with pytest.raises(e3.diff.EmptyDiffError):
e3.diff.patch("git_patch_with_header", cwd, discarded_files=["file*"])

assert not os.path.isfile("file1")
Expand Down

0 comments on commit 1c03c2f

Please sign in to comment.