diff --git a/app/build.gradle b/app/build.gradle
index 19adc562b..af89be656 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -53,6 +53,8 @@ android {
buildConfigField "boolean", "LOG_DEBUG", "false"
+ buildConfigField "String", "GIT_COMMIT", "\"${getCheckedOutGitCommitHash()}\""
+
// signingConfig signingConfigs.debug
}
@@ -60,6 +62,8 @@ android {
buildConfigField "boolean", "LOG_DEBUG", "true"
buildConfigField "String", "DROPBOX_REFRESH_TOKEN", gradle.ext.appProperties.getProperty("dropbox.refresh_token", '""')
+
+ buildConfigField "String", "GIT_COMMIT", "\"${getCheckedOutGitCommitHash()}\""
}
}
@@ -228,3 +232,22 @@ def orgJavaLocation() {
return "com.github.orgzly-revived:org-java:$versions.org_java"
}
}
+
+// https://gist.github.com/JonasGroeger/7620911
+def getCheckedOutGitCommitHash() {
+ def gitFolder = "$projectDir/../.git/"
+ def takeFromHash = 12
+ /*
+ * '.git/HEAD' contains either
+ * in case of detached head: the currently checked out commit hash
+ * otherwise: a reference to a file containing the current commit hash
+ */
+ def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
+ def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
+ // def isRef = head.length > 1 // ref: refs/heads/master
+
+ if(isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb
+
+ def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master
+ refHead.text.trim().take takeFromHash
+}
diff --git a/app/src/main/java/com/orgzly/android/ui/settings/SettingsFragment.kt b/app/src/main/java/com/orgzly/android/ui/settings/SettingsFragment.kt
index 57a1333ea..9d455ed83 100644
--- a/app/src/main/java/com/orgzly/android/ui/settings/SettingsFragment.kt
+++ b/app/src/main/java/com/orgzly/android/ui/settings/SettingsFragment.kt
@@ -77,6 +77,8 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
setupVersionPreference()
+ setupGitCommitPreference()
+
setDefaultStateForNewNote()
preference(R.string.pref_key_file_absolute_root)?.let {
@@ -142,6 +144,13 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP
}
}
+ private fun setupGitCommitPreference() {
+ preference(R.string.pref_key_git_commit)?.let { pref ->
+ /* Set summary to the current version string, appending suffix for the flavor. */
+ pref.summary = BuildConfig.GIT_COMMIT
+ }
+ }
+
/*
* Display custom preference's dialog.
*/
diff --git a/app/src/main/res/values/prefs_keys.xml b/app/src/main/res/values/prefs_keys.xml
index 4d2c14855..6785ef58f 100644
--- a/app/src/main/res/values/prefs_keys.xml
+++ b/app/src/main/res/values/prefs_keys.xml
@@ -587,6 +587,7 @@
pref_key_ssh_keygen
pref_key_ssh_show_public_key
pref_key_version
+ pref_key_git_commit
pref_key_reload_getting_started
pref_key_clear_database
diff --git a/app/src/main/res/xml/prefs_screen_developer.xml b/app/src/main/res/xml/prefs_screen_developer.xml
index efb8a859f..78d607989 100644
--- a/app/src/main/res/xml/prefs_screen_developer.xml
+++ b/app/src/main/res/xml/prefs_screen_developer.xml
@@ -2,6 +2,7 @@
+
+