Skip to content

Instantly share code, notes, and snippets.

@HoldYourWaffle
Forked from lordcodes/current-git-branch.gradle
Last active February 16, 2018 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HoldYourWaffle/a8f3bf0f5830674859e98e9a5a825094 to your computer and use it in GitHub Desktop.
Save HoldYourWaffle/a8f3bf0f5830674859e98e9a5a825094 to your computer and use it in GitHub Desktop.
Gradle function to get the current git branch
def getCurrentGitBranch() {
def gitBranch = "Unknown branch"
def workingDir = new File("${project.projectDir}")
def result = 'git rev-parse --abbrev-ref HEAD'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() == 0) gitBranch = result.text.trim()
return gitBranch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment