Last active
August 29, 2015 14:01
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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