Skip to content

Commit

Permalink
Improve up-to-date detection
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-gh committed Jul 13, 2015
1 parent 772bc89 commit 7a78575
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group = 'net.minecrell'
version = '0.6-SNAPSHOT'
version = '0.6'
description = 'A Gradle plugin to manage patches for Git repositories'

sourceCompatibility = 1.6
Expand Down
14 changes: 13 additions & 1 deletion src/main/groovy/net/minecrell/gitpatcher/Git.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@ class Git {
assert repo.exists()
}

String getStatus() {
return run('status', ['-z']) as String
}

String getRef() {
return show_ref('-s', 'HEAD') as String
}

Command run(String name, Object input) {
return new Command(['git', name.replace('_' as char, '-' as char), *input].execute(null as String[], repo))
}

@Override
Command invokeMethod(String name, Object input) {
return new Command(['git', name.replace('_' as char, '-' as char), *input].execute(null as String[], repo))
return run(name, input)
}

static class Command {
Expand Down
4 changes: 0 additions & 4 deletions src/main/groovy/net/minecrell/gitpatcher/task/GitTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ abstract class GitTask extends DefaultTask {

File repo

protected File getIndexFile() {
return new File(new File(repo, '.git'), 'index')
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,19 @@ class ApplyPatchesTask extends PatchTask {
}

@Override @OutputFile
File getIndexFile() {
return super.getIndexFile()
File getRefCache() {
return super.getRefCache()
}

{
outputs.upToDateWhen {
if (!repo.directory) {
return false
}

def git = new Git(repo)
return git.status.empty && cachedRef == git.ref
}
}

@TaskAction
Expand Down Expand Up @@ -76,6 +87,7 @@ class ApplyPatchesTask extends PatchTask {
logger.lifecycle 'Successfully applied patches from {} to {}', patchDir, repo
}

refCache.text = git.ref
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,26 @@ class MakePatchesTask extends PatchTask {
}

@Override @InputFile
File getIndexFile() {
return super.getIndexFile()
File getRefCache() {
return super.getRefCache()
}

@Override @OutputDirectory
File getPatchDir() {
return super.getPatchDir()
}

{
outputs.upToDateWhen {
if (!repo.directory) {
return false
}

def git = new Git(repo)
return cachedRef == git.ref
}
}

@TaskAction
void makePatches() {
if (patchDir.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ abstract class PatchTask extends SubmoduleTask {
return new File(root, submodule)
}

File getGitDir() {
return new File(repo, '.git')
}

File getRefCache() {
return new File(gitDir, '.gitpatcher_ref')
}

String getCachedRef() {
return refCache.file ? refCache.text : null
}

}

0 comments on commit 7a78575

Please sign in to comment.