Skip to content

Instantly share code, notes, and snippets.

@hypest
Last active December 6, 2018 12:11
Show Gist options
  • Save hypest/e06f6097065728b6db7b7c462f8fef1a to your computer and use it in GitHub Desktop.
Save hypest/e06f6097065728b6db7b7c462f8fef1a to your computer and use it in GitHub Desktop.
submoduleGitHash() implementation for gradle
def submoduleGitHash(workDir, gitSubmodulePath) {
def stdout = new ByteArrayOutputStream()
exec {
workingDir workDir
commandLine 'git', 'submodule', 'status', gitSubmodulePath
standardOutput = stdout
}
def submoduleStatus = stdout.toString().trim()
def match = (submoduleStatus =~ /^([-+]?)([a-z\d]*) ${gitSubmodulePath}/)
switch (match[0][1]) {
case '+':
logger.quiet("Important info: building against a [${gitSubmodulePath}] hash that is not matching the submodule.")
break;
case '-':
// submodule is not initialized yet, but that's not a problem, we'll use the referenced hash
break;
default:
// submodule is up-to-date. Nothing special here
break;
}
return match[0][2]
}
ext {
submoduleGitHash = this.&submoduleGitHash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment