Skip to content

Commit 6919035

Browse files
committed
Check PATH before trying to patch
1 parent e6b788c commit 6919035

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package net.minecrell.gitpatcher
2323

2424
import net.minecrell.gitpatcher.task.UpdateSubmodulesTask
25+
import net.minecrell.gitpatcher.task.FindGitTask
2526
import net.minecrell.gitpatcher.task.patch.ApplyPatchesTask
2627
import net.minecrell.gitpatcher.task.patch.MakePatchesTask
2728
import org.gradle.api.Plugin
@@ -39,14 +40,15 @@ class GitPatcher implements Plugin<Project> {
3940
this.extension = extensions.create('patches', PatchExtension)
4041
extension.root = projectDir
4142

42-
task('updateSubmodules', type: UpdateSubmodulesTask)
43-
task('applyPatches', type: ApplyPatchesTask) {
44-
dependsOn 'updateSubmodules'
45-
}
46-
task('makePatches', type: MakePatchesTask)
43+
task('findGit', type: FindGitTask)
44+
task('updateSubmodules', type: UpdateSubmodulesTask, dependsOn: 'findGit')
45+
task('applyPatches', type: ApplyPatchesTask, dependsOn: 'updateSubmodules')
46+
task('makePatches', type: MakePatchesTask, dependsOn: 'findGit')
4747

4848
afterEvaluate {
4949
// Configure the settings from our extension
50+
tasks.findGit.submodule = extension.submodule
51+
5052
configure([tasks.applyPatches, tasks.makePatches]) {
5153
repo = extension.target
5254
root = extension.root
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2015, Minecrell <https://github.com/Minecrell>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package net.minecrell.gitpatcher.task
23+
24+
import net.minecrell.gitpatcher.Git
25+
import org.gradle.api.DefaultTask
26+
import org.gradle.api.tasks.TaskAction
27+
28+
class FindGitTask extends DefaultTask {
29+
30+
String submodule
31+
32+
@TaskAction
33+
void findGit() {
34+
def git = new Git(project.projectDir)
35+
try {
36+
def version = (git.version() as String).readLines().join(', ')
37+
logger.lifecycle("Using $version for patching submodule $submodule.")
38+
} catch (Throwable e) {
39+
throw new AssertionError(
40+
'Failed to verify Git version. Make sure running the Gradle build in an environment where Git is in your PATH.', e);
41+
}
42+
}
43+
44+
}

0 commit comments

Comments
 (0)