aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-11-27 13:06:08 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-11-27 13:28:46 +0530
commit56a25dcd3231d2bf6aea98f0eda0a782afe91788 (patch)
treeff2763bceb8d648152f7c4396a5784fbfa514786 /app
parent74711fcc78c2f0aaf1f63d7c7414169fa22c47f3 (diff)
refactor: replace branch preference value with repository-based helper
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt5
-rw-r--r--app/src/main/java/app/passwordstore/ui/git/config/GitServerConfigActivity.kt3
-rw-r--r--app/src/main/java/app/passwordstore/util/git/operation/BreakOutOfDetached.kt6
-rw-r--r--app/src/main/java/app/passwordstore/util/git/operation/GitOperation.kt22
-rw-r--r--app/src/main/java/app/passwordstore/util/settings/GitSettings.kt13
-rw-r--r--app/src/main/java/app/passwordstore/util/settings/Migrations.kt13
-rw-r--r--app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt4
7 files changed, 26 insertions, 40 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt b/app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt
index 68684582..96a9d191 100644
--- a/app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/git/config/GitConfigActivity.kt
@@ -99,13 +99,14 @@ class GitConfigActivity : BaseGitActivity() {
launchGitOperation(GitOp.BREAK_OUT_OF_DETACHED)
.fold(
success = {
+ val branch = PasswordRepository.getCurrentBranch()
MaterialAlertDialogBuilder(this@GitConfigActivity).run {
setTitle(resources.getString(R.string.git_abort_and_push_title))
setMessage(
resources.getString(
R.string.git_break_out_of_detached_success,
- gitSettings.branch,
- "conflicting-${gitSettings.branch}-...",
+ branch,
+ "conflicting-$branch-...",
)
)
setOnDismissListener { finish() }
diff --git a/app/src/main/java/app/passwordstore/ui/git/config/GitServerConfigActivity.kt b/app/src/main/java/app/passwordstore/ui/git/config/GitServerConfigActivity.kt
index 5792645a..78f1aa2b 100644
--- a/app/src/main/java/app/passwordstore/ui/git/config/GitServerConfigActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/git/config/GitServerConfigActivity.kt
@@ -141,8 +141,7 @@ class GitServerConfigActivity : BaseGitActivity() {
val updateResult =
gitSettings.updateConnectionSettingsIfValid(
newAuthMode = newAuthMode,
- newUrl = binding.serverUrl.text.toString().trim(),
- newBranch = binding.serverBranch.text.toString().trim()
+ newUrl = binding.serverUrl.text.toString().trim()
)
) {
GitSettings.UpdateConnectionSettingsResult.FailedToParseUrl -> {
diff --git a/app/src/main/java/app/passwordstore/util/git/operation/BreakOutOfDetached.kt b/app/src/main/java/app/passwordstore/util/git/operation/BreakOutOfDetached.kt
index 2ce6f625..b6f31b18 100644
--- a/app/src/main/java/app/passwordstore/util/git/operation/BreakOutOfDetached.kt
+++ b/app/src/main/java/app/passwordstore/util/git/operation/BreakOutOfDetached.kt
@@ -6,6 +6,7 @@ package app.passwordstore.util.git.operation
import androidx.appcompat.app.AppCompatActivity
import app.passwordstore.R
+import app.passwordstore.data.repo.PasswordRepository
import app.passwordstore.util.extensions.unsafeLazy
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.eclipse.jgit.api.RebaseCommand
@@ -15,17 +16,18 @@ import org.eclipse.jgit.lib.RepositoryState
class BreakOutOfDetached(callingActivity: AppCompatActivity) : GitOperation(callingActivity) {
private val merging = repository.repositoryState == RepositoryState.MERGING
+ private val localBranch = PasswordRepository.getCurrentBranch()
private val resetCommands =
arrayOf(
// git checkout -b conflict-branch
git
.checkout()
.setCreateBranch(true)
- .setName("conflicting-$remoteBranch-${System.currentTimeMillis()}"),
+ .setName("conflicting-$localBranch-${System.currentTimeMillis()}"),
// push the changes
git.push().setRemote("origin"),
// switch back to ${gitBranch}
- git.checkout().setName(remoteBranch),
+ git.checkout().setName(localBranch),
)
override val commands by unsafeLazy {
diff --git a/app/src/main/java/app/passwordstore/util/git/operation/GitOperation.kt b/app/src/main/java/app/passwordstore/util/git/operation/GitOperation.kt
index 1a4a62df..e625a0bd 100644
--- a/app/src/main/java/app/passwordstore/util/git/operation/GitOperation.kt
+++ b/app/src/main/java/app/passwordstore/util/git/operation/GitOperation.kt
@@ -13,23 +13,20 @@ import app.passwordstore.data.repo.PasswordRepository
import app.passwordstore.ui.sshkeygen.SshKeyGenActivity
import app.passwordstore.ui.sshkeygen.SshKeyImportActivity
import app.passwordstore.util.auth.BiometricAuthenticator
-import app.passwordstore.util.auth.BiometricAuthenticator.Result.*
+import app.passwordstore.util.auth.BiometricAuthenticator.Result.Cancelled
+import app.passwordstore.util.auth.BiometricAuthenticator.Result.Failure
+import app.passwordstore.util.auth.BiometricAuthenticator.Result.Success
import app.passwordstore.util.git.GitCommandExecutor
import app.passwordstore.util.git.sshj.SshAuthMethod
import app.passwordstore.util.git.sshj.SshKey
import app.passwordstore.util.git.sshj.SshjSessionFactory
import app.passwordstore.util.settings.AuthMode
-import app.passwordstore.util.settings.GitSettings
import com.github.michaelbull.result.Err
import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.Result
import com.github.michaelbull.result.onFailure
import com.github.michaelbull.result.runCatching
import com.google.android.material.dialog.MaterialAlertDialogBuilder
-import dagger.hilt.EntryPoint
-import dagger.hilt.InstallIn
-import dagger.hilt.android.EntryPointAccessors
-import dagger.hilt.components.SingletonComponent
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
@@ -64,15 +61,8 @@ abstract class GitOperation(protected val callingActivity: FragmentActivity) {
open val requiresAuth: Boolean = true
private val hostKeyFile = callingActivity.filesDir.resolve(".host_key")
private var sshSessionFactory: SshjSessionFactory? = null
- private val hiltEntryPoint =
- EntryPointAccessors.fromApplication(
- callingActivity.applicationContext,
- GitOperationEntryPoint::class.java
- )
-
protected val repository = PasswordRepository.repository!!
protected val git = Git(repository)
- protected val remoteBranch = hiltEntryPoint.gitSettings().branch
private val authActivity
get() = callingActivity as AppCompatActivity
@@ -241,10 +231,4 @@ abstract class GitOperation(protected val callingActivity: FragmentActivity) {
/** Timeout in seconds before [TransportCommand] will abort a stalled IO operation. */
private const val CONNECT_TIMEOUT = 10
}
-
- @EntryPoint
- @InstallIn(SingletonComponent::class)
- interface GitOperationEntryPoint {
- fun gitSettings(): GitSettings
- }
}
diff --git a/app/src/main/java/app/passwordstore/util/settings/GitSettings.kt b/app/src/main/java/app/passwordstore/util/settings/GitSettings.kt
index ed1c02dc..048f021d 100644
--- a/app/src/main/java/app/passwordstore/util/settings/GitSettings.kt
+++ b/app/src/main/java/app/passwordstore/util/settings/GitSettings.kt
@@ -89,11 +89,6 @@ constructor(
set(value) {
settings.edit { putString(PreferenceKeys.GIT_CONFIG_AUTHOR_EMAIL, value) }
}
- var branch
- get() = settings.getString(PreferenceKeys.GIT_BRANCH_NAME) ?: DEFAULT_BRANCH
- private set(value) {
- settings.edit { putString(PreferenceKeys.GIT_BRANCH_NAME, value) }
- }
var useMultiplexing
get() = settings.getBoolean(PreferenceKeys.GIT_REMOTE_USE_MULTIPLEXING, true)
set(value) {
@@ -135,8 +130,7 @@ constructor(
fun updateConnectionSettingsIfValid(
newAuthMode: AuthMode,
- newUrl: String,
- newBranch: String
+ newUrl: String
): UpdateConnectionSettingsResult {
val parsedUrl =
runCatching { URIish(newUrl) }
@@ -167,7 +161,6 @@ constructor(
url = newUrl
authMode = newAuthMode
- branch = newBranch
return UpdateConnectionSettingsResult.Valid
}
@@ -178,8 +171,4 @@ constructor(
/** Returns true if a host key was previously saved */
fun hasSavedHostKey(): Boolean = File(hostKeyPath).exists()
-
- companion object {
- private const val DEFAULT_BRANCH = "master"
- }
}
diff --git a/app/src/main/java/app/passwordstore/util/settings/Migrations.kt b/app/src/main/java/app/passwordstore/util/settings/Migrations.kt
index 859e6360..4e9f9557 100644
--- a/app/src/main/java/app/passwordstore/util/settings/Migrations.kt
+++ b/app/src/main/java/app/passwordstore/util/settings/Migrations.kt
@@ -27,6 +27,15 @@ fun runMigrations(filesDirPath: String, sharedPrefs: SharedPreferences, gitSetti
migrateToClipboardHistory(sharedPrefs)
migrateToDiceware(sharedPrefs)
removeExternalStorageProperties(sharedPrefs)
+ removeCurrentBranchValue(sharedPrefs)
+}
+
+fun removeCurrentBranchValue(sharedPrefs: SharedPreferences) {
+ if (sharedPrefs.contains(PreferenceKeys.GIT_BRANCH_NAME)) {
+ return
+ }
+ logcat(TAG, INFO) { "Deleting now unused branch name preference" }
+ sharedPrefs.edit { remove(PreferenceKeys.GIT_BRANCH_NAME) }
}
private fun migrateToGitUrlBasedConfig(sharedPrefs: SharedPreferences, gitSettings: GitSettings) {
@@ -36,7 +45,6 @@ private fun migrateToGitUrlBasedConfig(sharedPrefs: SharedPreferences, gitSettin
val serverUser = sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_USERNAME) ?: ""
val serverPath = sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_LOCATION) ?: ""
val protocol = Protocol.fromString(sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_PROTOCOL))
-
// Whether we need the leading ssh:// depends on the use of a custom port.
val hostnamePart = serverHostname.removePrefix("ssh://")
val url =
@@ -83,8 +91,7 @@ private fun migrateToGitUrlBasedConfig(sharedPrefs: SharedPreferences, gitSettin
url == null ||
gitSettings.updateConnectionSettingsIfValid(
newAuthMode = gitSettings.authMode,
- newUrl = url,
- newBranch = gitSettings.branch
+ newUrl = url
) != GitSettings.UpdateConnectionSettingsResult.Valid
) {
logcat(TAG, ERROR) { "Failed to migrate to URL-based Git config, generated URL is invalid" }
diff --git a/app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt b/app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt
index cb143d1a..12ea0d76 100644
--- a/app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt
+++ b/app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt
@@ -25,8 +25,10 @@ object PreferenceKeys {
const val GIT_CONFIG = "git_config"
const val GIT_CONFIG_AUTHOR_EMAIL = "git_config_user_email"
const val GIT_CONFIG_AUTHOR_NAME = "git_config_user_name"
+
@Deprecated(message = "We're removing support for external storage")
const val GIT_EXTERNAL = "git_external"
+
@Deprecated(message = "We're removing support for external storage")
const val GIT_EXTERNAL_REPO = "git_external_repo"
const val GIT_EXTERNAL_MIGRATED = "git_external_migrated"
@@ -46,6 +48,8 @@ object PreferenceKeys {
@Deprecated("Use GIT_REMOTE_URL instead") const val GIT_REMOTE_USERNAME = "git_remote_username"
const val GIT_SERVER_INFO = "git_server_info"
+
+ @Deprecated("Git branch is no longer stored in preferences")
const val GIT_BRANCH_NAME = "git_branch"
const val HTTPS_PASSWORD = "https_password"
const val LENGTH = "length"