Skip to content

Commit 0a36d21

Browse files
committed
Add more up-to-date checks
1 parent 9a79715 commit 0a36d21

File tree

6 files changed

+53
-13
lines changed

6 files changed

+53
-13
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.2'
15+
version = '0.3'
1616
description = 'A Gradle plugin to manage patches for Git repositories'
1717

1818
sourceCompatibility = 1.6

src/main/groovy/net/minecrell/gitpatcher/git/Patcher.groovy

-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import static org.eclipse.jgit.revwalk.RevSort.TOPO
2727
import groovy.transform.stc.ClosureParams
2828
import groovy.transform.stc.FirstParam
2929
import groovy.transform.stc.SimpleType
30-
import org.apache.commons.lang.StringUtils
3130
import org.eclipse.jgit.api.Git
3231
import org.eclipse.jgit.diff.DiffFormatter
3332
import org.eclipse.jgit.revwalk.RevCommit
@@ -60,12 +59,6 @@ final class Patcher {
6059
return walk
6160
}
6261

63-
static File[] findPatches(File patchDir) {
64-
return patchDir.listFiles({ dir, name ->
65-
name.endsWith('.patch') && StringUtils.isNumeric(name.substring(0, 4))
66-
} as FilenameFilter).sort()
67-
}
68-
6962
static String suggestFileName(RevCommit commit, int num) {
7063
def result = new StringBuilder(String.format("%04d-", num))
7164
for (char c : commit.shortMessage.chars) {

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

+4
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ abstract class GitTask extends DefaultTask {
2727

2828
File repo
2929

30+
protected File getIndexFile() {
31+
return new File(new File(repo, '.git'), 'index')
32+
}
33+
3034
}

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

+19-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,29 @@ import static org.eclipse.jgit.api.ResetCommand.ResetType.HARD
2727
import static org.eclipse.jgit.submodule.SubmoduleWalk.getSubmoduleRepository
2828

2929
import net.minecrell.gitpatcher.git.MailPatch
30-
import net.minecrell.gitpatcher.git.Patcher
3130
import org.eclipse.jgit.api.Git
31+
import org.gradle.api.tasks.InputFiles
32+
import org.gradle.api.tasks.OutputDirectory
33+
import org.gradle.api.tasks.OutputFile
3234
import org.gradle.api.tasks.TaskAction
3335

3436
class ApplyPatchesTask extends PatchTask {
3537

38+
@Override @InputFiles
39+
File[] getPatches() {
40+
return super.getPatches()
41+
}
42+
43+
@Override @OutputDirectory
44+
File getRepo() {
45+
return super.getRepo()
46+
}
47+
48+
@Override @OutputFile
49+
File getIndexFile() {
50+
return super.getIndexFile()
51+
}
52+
3653
@TaskAction
3754
void applyPatches() {
3855
File source = null
@@ -73,7 +90,7 @@ class ApplyPatchesTask extends PatchTask {
7390
if (patchDir.isDirectory()) {
7491
logger.lifecycle 'Applying patches from {} to {}', patchDir, repo
7592

76-
for (def file : Patcher.findPatches(patchDir)) {
93+
for (def file : patches) {
7794
logger.lifecycle 'Applying: {}', file.name
7895

7996
def data = new ByteArrayInputStream(file.bytes)

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,41 @@ import net.minecrell.gitpatcher.git.MailPatch
2828
import net.minecrell.gitpatcher.git.Patcher
2929
import org.eclipse.jgit.diff.DiffFormatter
3030
import org.eclipse.jgit.patch.Patch
31+
import org.gradle.api.tasks.InputDirectory
32+
import org.gradle.api.tasks.InputFile
33+
import org.gradle.api.tasks.OutputDirectory
3134
import org.gradle.api.tasks.TaskAction
3235

3336
class MakePatchesTask extends PatchTask {
3437

38+
@Override @InputDirectory
39+
File getRepo() {
40+
return super.getRepo()
41+
}
42+
43+
@Override @InputFile
44+
File getIndexFile() {
45+
return super.getIndexFile()
46+
}
47+
48+
@Override @OutputDirectory
49+
File getPatchDir() {
50+
return super.getPatchDir()
51+
}
52+
3553
@TaskAction
3654
void makePatches() {
3755
File[] patches
3856
if (patchDir.isDirectory()) {
39-
patches = Patcher.findPatches(patchDir)
57+
patches = this.patches
4058
} else {
4159
assert patchDir.mkdirs(), 'Failed to create patch directory'
4260
patches = null
4361
}
4462

4563
openGit(repo) {
64+
didWork = false
65+
4666
def i = 0
4767
for (def commit : log(it, 'origin/upstream')) {
4868
def out = new File(patchDir, Patcher.suggestFileName(commit, i+1))
@@ -90,6 +110,7 @@ class MakePatchesTask extends PatchTask {
90110

91111

92112
logger.lifecycle 'Generating patch: {}', out.name
113+
didWork = true
93114

94115
out.createNewFile()
95116
out.withOutputStream {

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
package net.minecrell.gitpatcher.task.patch
2323

2424
import net.minecrell.gitpatcher.task.SubmoduleTask
25-
import org.gradle.api.tasks.InputDirectory
25+
import org.apache.commons.lang.StringUtils
2626

2727
abstract class PatchTask extends SubmoduleTask {
2828

2929
File root
3030

31-
@InputDirectory
3231
File patchDir
3332

33+
protected File[] getPatches() {
34+
return patchDir.listFiles({ dir, name ->
35+
name.endsWith('.patch') && StringUtils.isNumeric(name.substring(0, 4))
36+
} as FilenameFilter).sort()
37+
}
38+
3439
}

0 commit comments

Comments
 (0)