Skip to content

diffSource.git.compareWith ignores uncommitted files #73

@dbwiddis

Description

@dbwiddis

Describe the bug
The diffSource.git.compareWith configuration has no effect if the files have not been committed to git.

If this is by design, it should be clearly documented. However, it does not align with the expectation of executing git diff <ref> and saving the results to a file that the plugin points to. In particular, it makes a diff reference to HEAD completely useless after the commit.

Additionally the comment in the config explicitly specifies uncommitted files:

Compares current HEAD and all uncommited with provided branch

Desktop (please complete the following information):

  • OS: Mac OS X 13.0 x86_64
  • Gradle version: 7.5.1
  • Diff Coverage plugin version 0.9.5

To Reproduce

  1. Make changes to a file that require coverage, save them but do not commit.
  2. gradle diffCoverage with the below configuration
diffCoverageReport {
    diffSource {
        git.compareWith 'refs/remotes/origin/main'
    }

    reports {
        html = true
    }
}
  1. Observe the files in build/reports/jacoco directory:

Expected behavior

Changed files are found and diff.patch is not empty.

Additional context

Workaround is to configure:

    diffSource {
        file = 'build/tmp/git.diff'
    }

and then execute:

git diff refs/remotes/origin/main > build/tmp/git.diff
gradle diffCoverage

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions