Skip to content

Instantly share code, notes, and snippets.

@andreiRS
Created May 1, 2016 16:57
Show Gist options
  • Save andreiRS/417fd445abf11d787a2430d3dd9beef5 to your computer and use it in GitHub Desktop.
Save andreiRS/417fd445abf11d787a2430d3dd9beef5 to your computer and use it in GitHub Desktop.
Gradle task to print all local branches that contain a commit when CI uses detached head strategy
task printCommitBranches(type: Exec) {
executable "bash"
args "-c", "git branch --contains HEAD"
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
doLast {
// split the output of the git command per newline and remove indentation whitespaces
def outputLines = standardOutput.toString().split(/\r?\n\s+/)
// if detached head, remove the line
outputLines = outputLines.findAll({ it.contains("HEAD") == false })
print outputLines.join(",")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment