21
21
*/
22
22
package net.minecrell.gitpatcher.task.patch
23
23
24
+ import static java.lang.Boolean.parseBoolean
25
+ import static java.lang.System.getProperty
24
26
import static net.minecrell.gitpatcher.git.Patcher.withGit
25
27
import static org.eclipse.jgit.api.Git.wrap
26
28
import static org.eclipse.jgit.api.ResetCommand.ResetType.HARD
@@ -35,6 +37,8 @@ import org.gradle.api.tasks.TaskAction
35
37
36
38
class ApplyPatchesTask extends PatchTask {
37
39
40
+ private static final boolean JGIT_APPLY = parseBoolean(getProperty(" jgit.apply" , " true" ))
41
+
38
42
@Override @InputFiles
39
43
File [] getPatches () {
40
44
return super . getPatches()
@@ -90,23 +94,38 @@ class ApplyPatchesTask extends PatchTask {
90
94
if (patchDir. isDirectory()) {
91
95
logger. lifecycle ' Applying patches from {} to {}' , patchDir, repo
92
96
93
- for (def file : patches) {
94
- logger. lifecycle ' Applying: {}' , file. name
95
-
96
- def data = new ByteArrayInputStream (file. bytes)
97
- def patch = MailPatch . parseHeader(data)
98
- data. reset()
97
+ if (! JGIT_APPLY ) {
98
+ [' git' , ' am' , ' --abort' ]. execute(null as String [], repo). waitFor()
99
+ }
99
100
100
- apply(). setPatch(data). call()
101
- commit(). setAuthor(patch. author)
102
- .setMessage(patch. message)
103
- .setAll(true )
104
- .call()
101
+ for (def file : patches) {
102
+ if (JGIT_APPLY ) {
103
+ logger. lifecycle ' Applying: {}' , file. name
104
+
105
+ def data = new ByteArrayInputStream (file. bytes)
106
+ def patch = MailPatch . parseHeader(data)
107
+ data. reset()
108
+
109
+ apply(). setPatch(data). call()
110
+ commit(). setAuthor(patch. author)
111
+ .setMessage(patch. message)
112
+ .setAll(true )
113
+ .call()
114
+ } else {
115
+ def p = [' git' , ' am' , ' --3way' , file. absolutePath]. execute(null as String [], repo)
116
+ p. consumeProcessOutput(System . out as OutputStream , System . err)
117
+ def r = p. waitFor()
118
+ assert r == 0 , " Process returned error code $r "
119
+ }
105
120
}
106
121
107
122
logger. lifecycle ' Successfully applied patches from {} to {}' , patchDir, repo
108
123
}
109
124
}
110
125
}
111
126
127
+ private static void exec (List<String > command , File workingDir ) {
128
+ command. execute(null as String [], workingDir). consumeProcessOutput()
129
+ }
130
+
112
131
}
0 commit comments