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
30 changes: 14 additions & 16 deletions diff_cover/diff_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,22 +349,20 @@ def _parse_source_sections(self, diff_str):

# Every other line is stored in the dictionary for this source file
# once we find a hunk section
else:
# Only add lines if we're in a hunk section
# (ignore index and files changed lines)
if found_hunk or line.startswith("@@"):
# Remember that we found a hunk
found_hunk = True

if src_path is not None:
source_dict[src_path].append(line)

else:
# We tolerate other information before we have
# a source file defined, unless it's a hunk line
if line.startswith("@@"):
msg = f"Hunk has no source file: '{line}'"
raise GitDiffError(msg)
# Only add lines if we're in a hunk section
# (ignore index and files changed lines)
elif found_hunk or line.startswith("@@"):
# Remember that we found a hunk
found_hunk = True

if src_path is not None:
source_dict[src_path].append(line)

# We tolerate other information before we have
# a source file defined, unless it's a hunk line
elif line.startswith("@@"):
msg = f"Hunk has no source file: '{line}'"
raise GitDiffError(msg)

return source_dict

Expand Down
4 changes: 1 addition & 3 deletions diff_cover/git_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def diff_committed(self, compare_branch="origin/main"):
Raises a `GitDiffError` if `git diff` outputs anything
to stderr.
"""
diff_range = "{branch}{notation}HEAD".format(
branch=compare_branch, notation=self.range_notation
)
diff_range = f"{compare_branch}{self.range_notation}HEAD"
try:
return execute(
self._default_git_args + self._default_diff_args + [diff_range]
Expand Down