Skip to content

Commit

Permalink
Add Git commit hash info to developer settings
Browse files Browse the repository at this point in the history
  • Loading branch information
amberin committed Sep 8, 2024
1 parent 8f9c002 commit 7a1f7a6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ android {

buildConfigField "boolean", "LOG_DEBUG", "false"

buildConfigField "String", "GIT_COMMIT", "\"${getCheckedOutGitCommitHash()}\""

// signingConfig signingConfigs.debug
}

debug {
buildConfigField "boolean", "LOG_DEBUG", "true"

buildConfigField "String", "DROPBOX_REFRESH_TOKEN", gradle.ext.appProperties.getProperty("dropbox.refresh_token", '""')

buildConfigField "String", "GIT_COMMIT", "\"${getCheckedOutGitCommitHash()}\""
}
}

Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class SettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedP

setupVersionPreference()

setupGitCommitPreference()

setDefaultStateForNewNote()

preference(R.string.pref_key_file_absolute_root)?.let {
Expand Down Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/prefs_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@
<string name="pref_key_ssh_keygen" translatable="false">pref_key_ssh_keygen</string>
<string name="pref_key_ssh_show_public_key" translatable="false">pref_key_ssh_show_public_key</string>
<string name="pref_key_version" translatable="false">pref_key_version</string>
<string name="pref_key_git_commit" translatable="false">pref_key_git_commit</string>
<string name="pref_key_reload_getting_started" translatable="false">pref_key_reload_getting_started</string>
<string name="pref_key_clear_database" translatable="false">pref_key_clear_database</string>

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/prefs_screen_developer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/developer_options">

<SwitchPreference
Expand All @@ -25,4 +26,9 @@
android:targetClass="com.orgzly.android.ui.logs.AppLogsActivity"/>
</Preference>

<Preference
android:key="pref_key_git_commit"
android:title="Git commit of app build"
app:enableCopying="true" />

</androidx.preference.PreferenceScreen>

0 comments on commit 7a1f7a6

Please sign in to comment.