File tree Expand file tree Collapse file tree 6 files changed +42
-5
lines changed
src/main/groovy/net/minecrell/gitpatcher Expand file tree Collapse file tree 6 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ plugins {
1212}
1313
1414group = ' net.minecrell'
15- version = ' 0.6 '
15+ version = ' 0.7 '
1616description = ' A Gradle plugin to manage patches for Git repositories'
1717
1818sourceCompatibility = 1.6
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -28,10 +28,15 @@ import org.gradle.api.tasks.TaskAction
2828
2929class 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}
Original file line number Diff line number Diff line change @@ -24,13 +24,16 @@ package net.minecrell.gitpatcher.task.patch
2424import static java.lang.System.out
2525
2626import net.minecrell.gitpatcher.Git
27+ import net.minecrell.gitpatcher.task.UpdateSubmodulesTask
2728import org.gradle.api.tasks.InputFiles
2829import org.gradle.api.tasks.OutputDirectory
2930import org.gradle.api.tasks.OutputFile
3031import org.gradle.api.tasks.TaskAction
3132
3233class 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}
Original file line number Diff line number Diff line change 2121 */
2222package net.minecrell.gitpatcher.task.patch
2323
24+ import com.google.common.collect.ImmutableList
2425import net.minecrell.gitpatcher.task.SubmoduleTask
2526
2627abstract 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}
You can’t perform that action at this time.
0 commit comments