Skip to content

Commit 47da47e

Browse files
committed
Fix task reporting up-to-date if only submodule commit changed
1 parent 2d50c50 commit 47da47e

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
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'
15+
version = '0.7'
1616
description = 'A Gradle plugin to manage patches for Git repositories'
1717

1818
sourceCompatibility = 1.6

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Git {
3939
}
4040

4141
String getRef() {
42-
return show_ref('-s', 'HEAD') as String
42+
return (rev_parse('HEAD') as String).readLines().first().trim()
4343
}
4444

4545
Command run(String name, Object input) {

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

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class GitPatcher implements Plugin<Project> {
5454
patchDir = extension.patches
5555
}
5656

57+
tasks.applyPatches.updateTask = tasks.updateSubmodules
58+
5759
tasks.updateSubmodules.with {
5860
repo = extension.root
5961
submodule = extension.submodule

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

+9
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ import org.gradle.api.tasks.TaskAction
2828

2929
class UpdateSubmodulesTask extends SubmoduleTask {
3030

31+
private String ref
32+
3133
@TaskAction
3234
void updateSubmodules() {
3335
def git = new Git(repo)
3436
def result = git.submodule('status', '--', submodule) as String
37+
38+
this.ref = result[1 .. result.indexOf(' ', 1) - 1]
39+
3540
if (result.startsWith(' ')) {
3641
didWork = false
3742
return
@@ -40,4 +45,8 @@ class UpdateSubmodulesTask extends SubmoduleTask {
4045
git.submodule('update', '--init', '--recursive') >> out
4146
}
4247

48+
String getRef() {
49+
ref
50+
}
51+
4352
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ package net.minecrell.gitpatcher.task.patch
2424
import static java.lang.System.out
2525

2626
import net.minecrell.gitpatcher.Git
27+
import net.minecrell.gitpatcher.task.UpdateSubmodulesTask
2728
import org.gradle.api.tasks.InputFiles
2829
import org.gradle.api.tasks.OutputDirectory
2930
import org.gradle.api.tasks.OutputFile
3031
import org.gradle.api.tasks.TaskAction
3132

3233
class ApplyPatchesTask extends PatchTask {
3334

35+
UpdateSubmodulesTask updateTask
36+
3437
@Override @InputFiles
3538
File[] getPatches() {
3639
return super.getPatches()
@@ -53,7 +56,7 @@ class ApplyPatchesTask extends PatchTask {
5356
}
5457

5558
def git = new Git(repo)
56-
return git.status.empty && cachedRef == git.ref
59+
return git.status.empty && cachedRef == git.ref && cachedSubmoduleRef == updateTask.ref
5760
}
5861
}
5962

@@ -87,7 +90,7 @@ class ApplyPatchesTask extends PatchTask {
8790
logger.lifecycle 'Successfully applied patches from {} to {}', patchDir, repo
8891
}
8992

90-
refCache.text = git.ref
93+
refCache.text = git.ref + '\n' + updateTask.ref
9194
}
9295

9396
}

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package net.minecrell.gitpatcher.task.patch
2323

24+
import com.google.common.collect.ImmutableList
2425
import net.minecrell.gitpatcher.task.SubmoduleTask
2526

2627
abstract class PatchTask extends SubmoduleTask {
@@ -45,8 +46,30 @@ abstract class PatchTask extends SubmoduleTask {
4546
return new File(gitDir, '.gitpatcher_ref')
4647
}
4748

49+
private List<String> cachedRefs
50+
51+
private void readCache() {
52+
if (cachedRefs == null) {
53+
File refCache = this.refCache
54+
if (refCache.file) {
55+
this.cachedRefs = ImmutableList.copyOf refCache.readLines().findResults {
56+
def trimmed = it.trim()
57+
!trimmed.empty && !trimmed.startsWith('#') ? trimmed : null
58+
}
59+
} else {
60+
this.cachedRefs = ImmutableList.of()
61+
}
62+
}
63+
}
64+
4865
String getCachedRef() {
49-
return refCache.file ? refCache.text : null
66+
readCache()
67+
return cachedRefs[0]
68+
}
69+
70+
String getCachedSubmoduleRef() {
71+
readCache()
72+
return cachedRefs[1]
5073
}
5174

5275
}

0 commit comments

Comments
 (0)