diff --git a/diff_cover/diff_reporter.py b/diff_cover/diff_reporter.py index 411586e3..3ecf2cc9 100644 --- a/diff_cover/diff_reporter.py +++ b/diff_cover/diff_reporter.py @@ -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 diff --git a/diff_cover/git_diff.py b/diff_cover/git_diff.py index 86ced3fe..cf285519 100644 --- a/diff_cover/git_diff.py +++ b/diff_cover/git_diff.py @@ -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]