Last active
December 6, 2018 12:11
-
-
Save hypest/e06f6097065728b6db7b7c462f8fef1a to your computer and use it in GitHub Desktop.
submoduleGitHash() implementation for gradle
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
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