Browse Source

Grgit improvements

pull/61/merge
Ezerous 6 years ago
parent
commit
eb1a7f7889
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 26
      app/build.gradle
  2. 51
      app/gradle/grgit.gradle
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java

26
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'

51
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
}

4
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);

Loading…
Cancel
Save