diff --git a/app/build.gradle b/app/build.gradle index be0f9541..d13093bf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,6 @@ import groovy.json.JsonSlurper -import org.ajoberstar.grgit.Grgit + +apply from: 'gradle/grgit.gradle' apply plugin: 'com.android.application' apply plugin: 'io.fabric' @@ -17,6 +18,7 @@ android { archivesBaseName = "mTHMMY-v$versionName" buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\"" buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\"" + buildConfigField "boolean", "IS_CLEAN", String.valueOf(isClean()) } buildTypes { @@ -50,28 +52,6 @@ tasks.whenTaskAdded { task -> } } -static def getCurrentBranch() { - try { - def grgit = Grgit.open() - def curBranch = grgit.branch.getCurrent().name - grgit.close() - return curBranch - } catch (Exception ignored) { - return "" - } -} - -static def getCommitHash() { - try { - def grgit = Grgit.open() - def commitHash = grgit.head().id - grgit.close() - return commitHash - } catch (Exception ignored) { - return "" - } -} - dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0' diff --git a/app/gradle/grgit.gradle b/app/gradle/grgit.gradle new file mode 100644 index 00000000..d04a9a40 --- /dev/null +++ b/app/gradle/grgit.gradle @@ -0,0 +1,51 @@ +import org.ajoberstar.grgit.Grgit + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath 'org.ajoberstar.grgit:grgit-core:3.0.0-rc.2' + } +} + +static def getCurrentBranch() { + try { + def grgit = Grgit.open() + def currentBranch = grgit.branch.getCurrent().name + grgit.close() + return currentBranch + } catch (Exception ignored) { + return "" + } +} + +static def getCommitHash() { + try { + def grgit = Grgit.open() + def commitHash = grgit.head().id + grgit.close() + return commitHash + } catch (Exception ignored) { + return "" + } +} + +//Will return true if there are no uncommitted changes +static def isClean() { + try { + def grgit = Grgit.open() + def isClean = grgit.status().isClean() + grgit.close() + return isClean + } catch (Exception ignored) { + return true + } +} + +ext { + getCurrentBranch = this.&getCurrentBranch + getCommitHash = this.&getCommitHash + isClean = this.&isClean +} \ No newline at end of file diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java index 93016bc0..77a6aebd 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -50,7 +50,9 @@ public class AboutActivity extends BaseActivity { String versionInfo = ""; if(gitExists) - versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash + " "; + versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash + + (BuildConfig.IS_CLEAN ? "" : "-dirty") + + " "; // Avoid last letter being cut in italics styled TextView //Initialize appbar appBar = findViewById(R.id.appbar);