diff --git a/build.gradle b/build.gradle index a7d9988b58..6a49b0ce6e 100644 --- a/build.gradle +++ b/build.gradle @@ -89,6 +89,10 @@ allprojects{ return project.getProperties()["buildversion"] } + getCommitHash = { + return 'git rev-parse --verify --short HEAD'.execute().text.trim() + } + getPackage = { return project.ext.mainClassName.substring(0, project.ext.mainClassName.indexOf("desktop") - 1) } @@ -133,6 +137,10 @@ allprojects{ props["number"] = versionNumber props["modifier"] = versionModifier props["build"] = buildid + props["commitHash"] = "unknown" + if(project.hasProperty("showCommitHash")){ + props["commitHash"] = getCommitHash() + } props.store(pfile.newWriter(), "Autogenerated file. Do not modify.") } diff --git a/core/src/mindustry/core/Version.java b/core/src/mindustry/core/Version.java index 73bbd59416..c79594eebd 100644 --- a/core/src/mindustry/core/Version.java +++ b/core/src/mindustry/core/Version.java @@ -12,6 +12,8 @@ public class Version{ public static String type = "unknown"; /** Build modifier, e.g. 'alpha' or 'release' */ public static String modifier = "unknown"; + /** Git commit hash (short) */ + public static String commitHash = "unknown"; /** Number specifying the major version, e.g. '4' */ public static int number; /** Build number, e.g. '43'. set to '-1' for custom builds. */ @@ -32,6 +34,7 @@ public class Version{ type = map.get("type"); number = Integer.parseInt(map.get("number", "4")); modifier = map.get("modifier"); + commitHash = map.get("commitHash"); if(map.get("build").contains(".")){ String[] split = map.get("build").split("\\."); try{ @@ -73,6 +76,6 @@ public class Version{ if(build == -1){ return "custom build"; } - return (type.equals("official") ? modifier : type) + " build " + build + (revision == 0 ? "" : "." + revision); + return (type.equals("official") ? modifier : type) + " build " + build + (revision == 0 ? "" : "." + revision) + (commitHash.equals("unknown") ? "" : " (" + commitHash + ")"); } }