From 70aa41ae61fdfae1cbf2093cd5848c5808b08013 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 22 Aug 2020 18:13:06 +0530 Subject: Don't use git config for setting author and email (#1043) Fixes #1038 Signed-off-by: Harsh Shandilya --- .../com/zeapo/pwdstore/git/GitCommandExecutor.kt | 6 +++- .../com/zeapo/pwdstore/git/GitConfigActivity.kt | 2 -- .../com/zeapo/pwdstore/utils/PasswordRepository.kt | 42 ---------------------- 3 files changed, 5 insertions(+), 45 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt index e98f66ad..bf35e5c7 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt @@ -14,6 +14,7 @@ import com.google.android.material.snackbar.Snackbar import com.zeapo.pwdstore.R import com.zeapo.pwdstore.git.GitException.PullException import com.zeapo.pwdstore.git.GitException.PushException +import com.zeapo.pwdstore.git.config.GitSettings import com.zeapo.pwdstore.git.sshj.SshjSessionFactory import com.zeapo.pwdstore.git.operation.GitOperation import com.zeapo.pwdstore.utils.Result @@ -28,6 +29,7 @@ import org.eclipse.jgit.api.PullCommand import org.eclipse.jgit.api.PushCommand import org.eclipse.jgit.api.RebaseResult import org.eclipse.jgit.api.StatusCommand +import org.eclipse.jgit.lib.PersonIdent import org.eclipse.jgit.transport.RemoteRefUpdate import org.eclipse.jgit.transport.SshSessionFactory @@ -60,7 +62,9 @@ class GitCommandExecutor( // the previous status will eventually be used to avoid a commit if (nbChanges > 0) { withContext(Dispatchers.IO) { - command.call() + command + .setAuthor(PersonIdent(GitSettings.authorName, GitSettings.authorEmail)) + .call() } } } diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt index 5138b50b..9205e7fc 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt @@ -61,8 +61,6 @@ class GitConfigActivity : BaseGitActivity() { } else { GitSettings.authorEmail = email GitSettings.authorName = name - PasswordRepository.setGitAuthorEmail(email) - PasswordRepository.setGitAuthorName(name) Snackbar.make(binding.root, getString(R.string.git_server_config_save_success), Snackbar.LENGTH_SHORT).show() Handler().postDelayed(500) { finish() } } diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt index 45453d4f..f0b891fc 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -244,47 +244,5 @@ open class PasswordRepository protected constructor() { passwordList.sortWith(sortOrder.comparator) return passwordList } - - /** - * Sets the git user name - * - * @param username username - */ - @JvmStatic - fun setGitAuthorName(username: String) { - setStringConfig("user", null, "name", username) - } - - /** - * Sets the git user email - * - * @param email email - */ - @JvmStatic - fun setGitAuthorEmail(email: String) { - setStringConfig("user", null, "email", email) - } - - /** - * Sets a git config value - * - * @param section config section name - * @param subsection config subsection name - * @param name config name - * @param value the value to be set - */ - @JvmStatic - @Suppress("SameParameterValue") - private fun setStringConfig(section: String, subsection: String?, name: String, value: String) { - if (isInitialized) { - val config = repository!!.config - config.setString(section, subsection, name, value) - try { - config.save() - } catch (e: Exception) { - e.printStackTrace() - } - } - } } } -- cgit v1.2.3