mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-09-01 06:45:19 +00:00
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:
@@ -14,6 +14,7 @@ import com.google.android.material.snackbar.Snackbar
|
|||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.git.GitException.PullException
|
import com.zeapo.pwdstore.git.GitException.PullException
|
||||||
import com.zeapo.pwdstore.git.GitException.PushException
|
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.sshj.SshjSessionFactory
|
||||||
import com.zeapo.pwdstore.git.operation.GitOperation
|
import com.zeapo.pwdstore.git.operation.GitOperation
|
||||||
import com.zeapo.pwdstore.utils.Result
|
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.PushCommand
|
||||||
import org.eclipse.jgit.api.RebaseResult
|
import org.eclipse.jgit.api.RebaseResult
|
||||||
import org.eclipse.jgit.api.StatusCommand
|
import org.eclipse.jgit.api.StatusCommand
|
||||||
|
import org.eclipse.jgit.lib.PersonIdent
|
||||||
import org.eclipse.jgit.transport.RemoteRefUpdate
|
import org.eclipse.jgit.transport.RemoteRefUpdate
|
||||||
import org.eclipse.jgit.transport.SshSessionFactory
|
import org.eclipse.jgit.transport.SshSessionFactory
|
||||||
|
|
||||||
@@ -60,7 +62,9 @@ class GitCommandExecutor(
|
|||||||
// the previous status will eventually be used to avoid a commit
|
// the previous status will eventually be used to avoid a commit
|
||||||
if (nbChanges > 0) {
|
if (nbChanges > 0) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
command.call()
|
command
|
||||||
|
.setAuthor(PersonIdent(GitSettings.authorName, GitSettings.authorEmail))
|
||||||
|
.call()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -61,8 +61,6 @@ class GitConfigActivity : BaseGitActivity() {
|
|||||||
} else {
|
} else {
|
||||||
GitSettings.authorEmail = email
|
GitSettings.authorEmail = email
|
||||||
GitSettings.authorName = name
|
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()
|
Snackbar.make(binding.root, getString(R.string.git_server_config_save_success), Snackbar.LENGTH_SHORT).show()
|
||||||
Handler().postDelayed(500) { finish() }
|
Handler().postDelayed(500) { finish() }
|
||||||
}
|
}
|
||||||
|
@@ -244,47 +244,5 @@ open class PasswordRepository protected constructor() {
|
|||||||
passwordList.sortWith(sortOrder.comparator)
|
passwordList.sortWith(sortOrder.comparator)
|
||||||
return passwordList
|
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user