Skip to content

Commit 54b97c1

Browse files
committed
Add docs.
1 parent 750992f commit 54b97c1

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

IF_GIT_DIFF.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# If Git Diff
2+
<!---freshmark shields
3+
output = [
4+
link(shield('Gradle plugin', 'plugins.gradle.org', 'com.diffplug.if-git-diff', 'blue'), 'https://plugins.gradle.org/plugin/com.diffplug.if-git-diff'),
5+
link(shield('Maven central', 'mavencentral', 'available', 'blue'), 'https://search.maven.org/search?q=g:com.diffplug.spotless-changelog'),
6+
link(shield('Apache 2.0', 'license', 'apache-2.0', 'blue'), 'https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)'),
7+
'',
8+
link(shield('Changelog', 'changelog', versionLast, 'brightgreen'), 'CHANGELOG.md'),
9+
link(shield('Javadoc', 'javadoc', 'yes', 'brightgreen'), 'https://javadoc.jitpack.io/com/github/diffplug/spotless-changelog/spotless-changelog-agg/release~{{versionLast}}/javadoc/'),
10+
link(shield('Live chat', 'gitter', 'chat', 'brightgreen'), 'https://gitter.im/diffplug/spotless-changelog'),
11+
link(image('CircleCI', 'https://circleci.com/gh/diffplug/spotless-changelog.svg?style=shield'), 'https://circleci.com/gh/diffplug/spotless-changelog')
12+
].join('\n');
13+
-->
14+
[![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.if--git--diff-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.if-git-diff)
15+
[![Maven central](https://img.shields.io/badge/mavencentral-available-blue.svg)](https://search.maven.org/search?q=g:com.diffplug.spotless-changelog)
16+
[![Apache 2.0](https://img.shields.io/badge/license-apache--2.0-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
17+
18+
[![Changelog](https://img.shields.io/badge/changelog-2.3.2-brightgreen.svg)](CHANGELOG.md)
19+
[![Javadoc](https://img.shields.io/badge/javadoc-yes-brightgreen.svg)](https://javadoc.jitpack.io/com/github/diffplug/spotless-changelog/spotless-changelog-agg/release~2.3.2/javadoc/)
20+
[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless-changelog)
21+
[![CircleCI](https://circleci.com/gh/diffplug/spotless-changelog.svg?style=shield)](https://circleci.com/gh/diffplug/spotless-changelog)
22+
<!---freshmark /shields -->
23+
24+
This plugin can be applied in `settings.gradle` or `build.gradle`, and it lets you execute a block of code contingent on whether there are changes in the given folder relative to a given baseline git ref.
25+
26+
```gradle
27+
plugins {
28+
id 'com.diffplug.if-git-diff'
29+
}
30+
ifGitDiff {
31+
baseline 'origin/main' // default value
32+
inFolder 'a', { include 'a' }
33+
inFolder 'b', { include 'b' }
34+
}
35+
```
36+
37+
## Limitations
38+
39+
This plugin does not work well with the configuration cache. Using the example above:
40+
41+
- run `gradlew test` on a clean checkout of `origin/main`, and you would see that `:test` ran but `:a:test` and `:b:test` did not; so far so good.
42+
- now add a file `a/blah`
43+
- now if you run `gradlew test`
44+
- without configuration-cache -> `:test` and `:a:test` -> good!
45+
- with configuration-cache -> only `:test` -> bad, cached configuration doesn't know that `a/blah` was added
46+
47+
A different approach which could work with configuration-cache is to mark tasks as up-to-date based on git status, see the [`GitDiffUpToDatePlugin`](https://github.com/thahnen/GitDiffUpToDatePlugin) for that.
48+
49+
## Roadmap
50+
51+
This plugin was built to solve [a fairly specific problem in the Spotless build](https://github.com/diffplug/spotless-changelog/issues/30). It is packaged with `spotless-changelog` because it's vaguely related, and it might make sense someday for `spotless-changelog` to assert "if files changed in X dir, then changelog Y must be updated".
52+
53+
## Reference
54+
55+
<!---freshmark version
56+
output = prefixDelimiterReplace(input, "id 'com.diffplug.spotless-changelog' version '", "'", versionLast)
57+
output = prefixDelimiterReplace(output, 'https://github.com/diffplug/spotless-changelog/blob/release/', '/spotless', versionLast)
58+
output = prefixDelimiterReplace(output, 'https://javadoc.io/static/com.diffplug.spotless-changelog/spotless-changelog-plugin-gradle/', '/', versionLast)
59+
-->
60+
61+
[Plugin DSL javadoc](https://javadoc.io/static/com.diffplug.spotless-changelog/spotless-changelog-plugin-gradle/2.3.2/com/diffplug/spotless/changelog/gradle/IfGitDiffExtension.html). For requirements see [spotless-changelog](https://github.com/diffplug/spotless-changelog#requirements).
62+
63+
<!---freshmark /version -->
64+
65+
## Acknowledgments
66+
67+
- Git stuff by [jgit](https://www.eclipse.org/jgit/).
68+
- Built by [gradle](https://gradle.org/).
69+
- Maintained by [DiffPlug](https://www.diffplug.com/).

0 commit comments

Comments
 (0)