File tree 6 files changed +42
-5
lines changed
src/main/groovy/net/minecrell/gitpatcher
6 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ plugins {
12
12
}
13
13
14
14
group = ' net.minecrell'
15
- version = ' 0.6 '
15
+ version = ' 0.7 '
16
16
description = ' A Gradle plugin to manage patches for Git repositories'
17
17
18
18
sourceCompatibility = 1.6
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ class Git {
39
39
}
40
40
41
41
String getRef () {
42
- return show_ref( ' -s ' , ' HEAD' ) as String
42
+ return (rev_parse( ' HEAD' ) as String ) . readLines() . first() . trim()
43
43
}
44
44
45
45
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> {
54
54
patchDir = extension. patches
55
55
}
56
56
57
+ tasks. applyPatches. updateTask = tasks. updateSubmodules
58
+
57
59
tasks. updateSubmodules. with {
58
60
repo = extension. root
59
61
submodule = extension. submodule
Original file line number Diff line number Diff line change @@ -28,10 +28,15 @@ import org.gradle.api.tasks.TaskAction
28
28
29
29
class UpdateSubmodulesTask extends SubmoduleTask {
30
30
31
+ private String ref
32
+
31
33
@TaskAction
32
34
void updateSubmodules () {
33
35
def git = new Git (repo)
34
36
def result = git. submodule(' status' , ' --' , submodule) as String
37
+
38
+ this . ref = result[1 .. result. indexOf(' ' , 1 ) - 1 ]
39
+
35
40
if (result. startsWith(' ' )) {
36
41
didWork = false
37
42
return
@@ -40,4 +45,8 @@ class UpdateSubmodulesTask extends SubmoduleTask {
40
45
git. submodule(' update' , ' --init' , ' --recursive' ) >> out
41
46
}
42
47
48
+ String getRef () {
49
+ ref
50
+ }
51
+
43
52
}
Original file line number Diff line number Diff line change @@ -24,13 +24,16 @@ package net.minecrell.gitpatcher.task.patch
24
24
import static java.lang.System.out
25
25
26
26
import net.minecrell.gitpatcher.Git
27
+ import net.minecrell.gitpatcher.task.UpdateSubmodulesTask
27
28
import org.gradle.api.tasks.InputFiles
28
29
import org.gradle.api.tasks.OutputDirectory
29
30
import org.gradle.api.tasks.OutputFile
30
31
import org.gradle.api.tasks.TaskAction
31
32
32
33
class ApplyPatchesTask extends PatchTask {
33
34
35
+ UpdateSubmodulesTask updateTask
36
+
34
37
@Override @InputFiles
35
38
File [] getPatches () {
36
39
return super . getPatches()
@@ -53,7 +56,7 @@ class ApplyPatchesTask extends PatchTask {
53
56
}
54
57
55
58
def git = new Git (repo)
56
- return git. status. empty && cachedRef == git. ref
59
+ return git. status. empty && cachedRef == git. ref && cachedSubmoduleRef == updateTask . ref
57
60
}
58
61
}
59
62
@@ -87,7 +90,7 @@ class ApplyPatchesTask extends PatchTask {
87
90
logger. lifecycle ' Successfully applied patches from {} to {}' , patchDir, repo
88
91
}
89
92
90
- refCache. text = git. ref
93
+ refCache. text = git. ref + ' \n ' + updateTask . ref
91
94
}
92
95
93
96
}
Original file line number Diff line number Diff line change 21
21
*/
22
22
package net.minecrell.gitpatcher.task.patch
23
23
24
+ import com.google.common.collect.ImmutableList
24
25
import net.minecrell.gitpatcher.task.SubmoduleTask
25
26
26
27
abstract class PatchTask extends SubmoduleTask {
@@ -45,8 +46,30 @@ abstract class PatchTask extends SubmoduleTask {
45
46
return new File (gitDir, ' .gitpatcher_ref' )
46
47
}
47
48
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
+
48
65
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 ]
50
73
}
51
74
52
75
}
You can’t perform that action at this time.
0 commit comments