Andrey Hihlovskiy

Professional blog on groovy, gradle, Java, Javascript and other stuff.

Automated git-pull

Suppose you have 20 git-repositories, which you actively pull and push from/to central location (e.g. github). Don’t you think pulling them by hand is too mechanical? And what if you forget to pull some?

I wrote little gradle script capable of automated git-pull:

buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.ajoberstar:gradle-git:0.5.0' }
}
import org.ajoberstar.gradle.git.tasks.*
def onEachGitFolder(File folder, Closure closure) {
File gitServiceFolder = new File(folder, ".git")
if(gitServiceFolder.exists() && gitServiceFolder.isDirectory())
closure(folder)
else
folder.eachDir { subFolder ->
onEachGitFolder(subFolder, closure);
}
}
task pull
onEachGitFolder projectDir, { folder ->
def taskName = folder.name + "_pull"
project.task (taskName, type: GitPull) {
setRepoPath folder.absolutePath
}
project.tasks.pull.dependsOn project.tasks[taskName]
}
defaultTasks "pull"

view raw
git-pull.gradle
hosted with ❤ by GitHub

You drink morning coffee and the machine does the job for you.

Credits come to the creators of excellent gradle-git plugin:

https://github.com/ajoberstar/gradle-git

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: