Skip to content

Instantly share code, notes, and snippets.

@bugs84
Created October 9, 2015 13:36
Show Gist options
  • Save bugs84/529f1582eb1189d09a25 to your computer and use it in GitHub Desktop.
Save bugs84/529f1582eb1189d09a25 to your computer and use it in GitHub Desktop.
Gradle get hg mercurial changeset revision
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.aragost.javahg:javahg:0.4'
}
}
task revision << {
println "Build revision: $scmRevision"
}
import com.aragost.javahg.Changeset
import com.aragost.javahg.Repository
import com.aragost.javahg.commands.ParentsCommand
String getHgRevision() {
def repo = Repository.open(projectDir)
def parentsCommand = new ParentsCommand(repo)
List<Changeset> changesets = parentsCommand.execute()
if (changesets == null || changesets.size() != 1) {
def message = "Exactly one was parent expected. " + changesets
throw new Exception(message)
}
return changesets[0].node
}
ext {
scmRevision = getHgRevision()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment