Skip to content

Instantly share code, notes, and snippets.

@judoole
Last active August 29, 2015 14:01
Show Gist options
  • Save judoole/d5c29bdd21f676d2f374 to your computer and use it in GitHub Desktop.
Save judoole/d5c29bdd21f676d2f374 to your computer and use it in GitHub Desktop.
GGG. Gradle, Groovy and Git. Slap this inside your Gradle-script and you've rolled your own git-plugin.
class GitContext {
@Lazy String branchName = {
def proc = 'git rev-parse --abbrev-ref HEAD'.execute()
proc.waitFor()
assert proc.exitValue() == 0, proc.err.text
return proc.in.text.trim()
}()
def boolean isMasterBranch() {
return branchName == "master"
}
@Lazy String revision = {
def proc = 'git rev-parse --short HEAD'.execute()
proc.waitFor()
assert proc.exitValue() == 0, proc.err.text
return proc.in.text.trim()
}()
@Lazy String lastCommitter = {
def proc = 'git log -1 --format=%cE'.execute()
proc.waitFor()
assert proc.exitValue() == 0, proc.err.text
return proc.in.text.trim()
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment