Amethyst-Android/build.gradle
alexytomi eb8b2c3475 fix(build): getGitHash didn't use the correct hash
This change finally solves the problem it was meant to solve
2025-04-24 23:17:32 +08:00

34 lines
1009 B
Groovy

import java.io.IOException
plugins{
id 'com.android.application' version '8.7.2' apply false
id 'com.android.library' version '8.7.2' apply false
}
String getGitHash(String project) {
def command = Runtime.getRuntime().exec("git rev-list -1 HEAD " + project + "/src")
def returnCode = command.waitFor()
if (returnCode != 0) {
throw new IOException("Command 'getGitHash()' exited with " + returnCode)
}
String gitCommitHash = command.inputStream.text.trim()
return gitCommitHash
}
Boolean gitUsed() {
def returnCode = Runtime.getRuntime().exec("git rev-parse --is-inside-work-tree").waitFor()
switch(returnCode){
case 127:
println("git not found");
return false;
break;
case 128:
println("not inside a git repository");
return false;
break;
case 0:
return true;
default:
throw new IOException("Command 'gitUsed()' exited with " + returnCode)
}
}