Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions diff_cover/git_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,10 @@ def diff_committed(self, compare_branch="origin/main"):
)[0]
except CommandError as e:
if "unknown revision" in str(e):
raise ValueError(
dedent(
f"""
raise ValueError(dedent(f"""
Could not find the branch to compare to. Does '{compare_branch}' exist?
the `--compare-branch` argument allows you to set a different branch.
"""
)
) from e
""")) from e
raise

def diff_unstaged(self):
Expand Down
2 changes: 1 addition & 1 deletion diff_cover/violationsreporters/violations_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def parse_reports(self, reports):
# Ignore any line that isn't matched
# (for example, snippets from the source code)
if match is not None:
(cppcheck_src_path, line_number, message) = match.groups()
cppcheck_src_path, line_number, message = match.groups()

violation = Violation(int(line_number), message)
violations_dict[util.to_unix_path(cppcheck_src_path)].append(
Expand Down
84 changes: 45 additions & 39 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pyflakes = "^3.3.2"
pylint = ">=3.3.4,<5.0.0"
pylint-pytest = "^1.1.8"
pydocstyle = "^6.1.1"
black = "^25.1.0"
black = "^26.1.0"
isort = ">=6.0.1,<8.0.0"
doc8 = "2.0.0"
ruff = ">=0.11.10,<0.15.0"
Expand Down
48 changes: 16 additions & 32 deletions tests/test_diff_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ def test_ignore_lines_outside_src(diff, git_diff):
def test_one_line_file(diff, git_diff):
# Files with only one line have a special format
# in which the "length" part of the hunk is not specified
diff_str = dedent(
"""
diff_str = dedent("""
diff --git a/diff_cover/one_line.txt b/diff_cover/one_line.txt
index 0867e73..9daeafb 100644
--- a/diff_cover/one_line.txt
Expand All @@ -256,8 +255,7 @@ def test_one_line_file(diff, git_diff):
test
-test
-test
"""
).strip()
""").strip()

# Configure the git diff output
_set_git_diff_output(diff, git_diff, diff_str, "", "")
Expand Down Expand Up @@ -291,8 +289,7 @@ def test_git_deleted_lines(diff, git_diff):
def test_git_unicode_filename(diff, git_diff):
# Filenames with unicode characters have double quotes surrounding them
# in the git diff output.
diff_str = dedent(
"""
diff_str = dedent("""
diff --git "a/unic\303\270\342\210\202e\314\201.txt" "b/unic\303\270\342\210\202e\314\201.txt"
new file mode 100644
index 0000000..248ebea
Expand All @@ -302,8 +299,7 @@ def test_git_unicode_filename(diff, git_diff):
+μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος
+οὐλομένην, ἣ μυρί᾽ Ἀχαιοῖς ἄλγε᾽ ἔθηκε,
+πολλὰς δ᾽ ἰφθίμους ψυχὰς Ἄϊδι προΐαψεν
"""
).strip()
""").strip()

_set_git_diff_output(diff, git_diff, diff_str, "", "")
# Get the lines changed in the diff
Expand Down Expand Up @@ -429,28 +425,22 @@ def test_git_diff_error(
diff,
git_diff,
):
invalid_hunk_str = dedent(
"""
invalid_hunk_str = dedent("""
diff --git a/subdir/file1.py b/subdir/file1.py
@@ invalid @@ Text
"""
).strip()
""").strip()

no_src_line_str = "@@ -33,10 +34,13 @@ Text"

non_numeric_lines = dedent(
"""
non_numeric_lines = dedent("""
diff --git a/subdir/file1.py b/subdir/file1.py
@@ -1,2 +a,b @@
"""
).strip()
""").strip()

missing_line_num = dedent(
"""
missing_line_num = dedent("""
diff --git a/subdir/file1.py b/subdir/file1.py
@@ -1,2 + @@
"""
).strip()
""").strip()

missing_src_str = "diff --git "

Expand Down Expand Up @@ -478,16 +468,14 @@ def test_git_diff_error(

def test_plus_sign_in_hunk_bug(diff, git_diff):
# This was a bug that caused a parse error
diff_str = dedent(
"""
diff_str = dedent("""
diff --git a/file.py b/file.py
@@ -16,16 +16,7 @@ 1 + 2
+ test
+ test
+ test
+ test
"""
)
""")

_set_git_diff_output(diff, git_diff, diff_str, "", "")

Expand All @@ -498,16 +486,14 @@ def test_plus_sign_in_hunk_bug(diff, git_diff):
def test_terminating_chars_in_hunk(diff, git_diff):
# Check what happens when there's an @@ symbol after the
# first terminating @@ symbol
diff_str = dedent(
"""
diff_str = dedent("""
diff --git a/file.py b/file.py
@@ -16,16 +16,7 @@ and another +23,2 @@ symbol
+ test
+ test
+ test
+ test
"""
)
""")

_set_git_diff_output(diff, git_diff, diff_str, "", "")

Expand All @@ -518,8 +504,7 @@ def test_terminating_chars_in_hunk(diff, git_diff):
def test_merge_conflict_diff(diff, git_diff):
# Handle different git diff format when in the middle
# of a merge conflict
diff_str = dedent(
"""
diff_str = dedent("""
diff --cc subdir/src.py
index d2034c0,e594d54..0000000
diff --cc subdir/src.py
Expand All @@ -531,8 +516,7 @@ def test_merge_conflict_diff(diff, git_diff):
++<<<<<< HEAD
+ test
++=======
"""
)
""")

_set_git_diff_output(diff, git_diff, diff_str, "", "")

Expand Down
Loading
Loading