Don't use git config for setting author and email (#1043)

Fixes #1038

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-08-22 18:13:06 +05:30 committed by GitHub
parent 70f7d3b199
commit 70aa41ae61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 45 deletions

View file

@ -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()
}
}
}

View file

@ -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() }
}

View file

@ -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()
}
}
}
}
}