Skip to content

Commit 7a78575

Browse files
committed
Improve up-to-date detection
1 parent 772bc89 commit 7a78575

File tree

6 files changed

+53
-10
lines changed

6 files changed

+53
-10
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group = 'net.minecrell'
15-
version = '0.6-SNAPSHOT'
15+
version = '0.6'
1616
description = 'A Gradle plugin to manage patches for Git repositories'
1717

1818
sourceCompatibility = 1.6

src/main/groovy/net/minecrell/gitpatcher/Git.groovy

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,21 @@ class Git {
3434
assert repo.exists()
3535
}
3636

37+
String getStatus() {
38+
return run('status', ['-z']) as String
39+
}
40+
41+
String getRef() {
42+
return show_ref('-s', 'HEAD') as String
43+
}
44+
45+
Command run(String name, Object input) {
46+
return new Command(['git', name.replace('_' as char, '-' as char), *input].execute(null as String[], repo))
47+
}
48+
3749
@Override
3850
Command invokeMethod(String name, Object input) {
39-
return new Command(['git', name.replace('_' as char, '-' as char), *input].execute(null as String[], repo))
51+
return run(name, input)
4052
}
4153

4254
static class Command {

src/main/groovy/net/minecrell/gitpatcher/task/GitTask.groovy

-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,4 @@ abstract class GitTask extends DefaultTask {
2727

2828
File repo
2929

30-
protected File getIndexFile() {
31-
return new File(new File(repo, '.git'), 'index')
32-
}
33-
3430
}

src/main/groovy/net/minecrell/gitpatcher/task/patch/ApplyPatchesTask.groovy

+14-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,19 @@ class ApplyPatchesTask extends PatchTask {
4242
}
4343

4444
@Override @OutputFile
45-
File getIndexFile() {
46-
return super.getIndexFile()
45+
File getRefCache() {
46+
return super.getRefCache()
47+
}
48+
49+
{
50+
outputs.upToDateWhen {
51+
if (!repo.directory) {
52+
return false
53+
}
54+
55+
def git = new Git(repo)
56+
return git.status.empty && cachedRef == git.ref
57+
}
4758
}
4859

4960
@TaskAction
@@ -76,6 +87,7 @@ class ApplyPatchesTask extends PatchTask {
7687
logger.lifecycle 'Successfully applied patches from {} to {}', patchDir, repo
7788
}
7889

90+
refCache.text = git.ref
7991
}
8092

8193
}

src/main/groovy/net/minecrell/gitpatcher/task/patch/MakePatchesTask.groovy

+13-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,26 @@ class MakePatchesTask extends PatchTask {
3939
}
4040

4141
@Override @InputFile
42-
File getIndexFile() {
43-
return super.getIndexFile()
42+
File getRefCache() {
43+
return super.getRefCache()
4444
}
4545

4646
@Override @OutputDirectory
4747
File getPatchDir() {
4848
return super.getPatchDir()
4949
}
5050

51+
{
52+
outputs.upToDateWhen {
53+
if (!repo.directory) {
54+
return false
55+
}
56+
57+
def git = new Git(repo)
58+
return cachedRef == git.ref
59+
}
60+
}
61+
5162
@TaskAction
5263
void makePatches() {
5364
if (patchDir.isDirectory()) {

src/main/groovy/net/minecrell/gitpatcher/task/patch/PatchTask.groovy

+12
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@ abstract class PatchTask extends SubmoduleTask {
3737
return new File(root, submodule)
3838
}
3939

40+
File getGitDir() {
41+
return new File(repo, '.git')
42+
}
43+
44+
File getRefCache() {
45+
return new File(gitDir, '.gitpatcher_ref')
46+
}
47+
48+
String getCachedRef() {
49+
return refCache.file ? refCache.text : null
50+
}
51+
4052
}

0 commit comments

Comments
 (0)