Restore workaround for preventing empty commits (#1019)
* Revert "Add symlink support to JGit (#1016)"
This reverts commit 5032696cec
.
* Restore workaround for empty commits and document commands
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
* Update app/src/main/java/com/zeapo/pwdstore/git/GitCommandExecutor.kt
This commit is contained in:
parent
2732f9093e
commit
57f1c65fdf
7 changed files with 41 additions and 28 deletions
|
@ -118,8 +118,6 @@ dependencies {
|
||||||
implementation(Dependencies.ThirdParty.jgit) {
|
implementation(Dependencies.ThirdParty.jgit) {
|
||||||
exclude(group = "org.apache.httpcomponents", module = "httpclient")
|
exclude(group = "org.apache.httpcomponents", module = "httpclient")
|
||||||
}
|
}
|
||||||
// Loaded dynamically by JGit to provide symlink support
|
|
||||||
implementation(Dependencies.ThirdParty.jgit_java7)
|
|
||||||
implementation(Dependencies.ThirdParty.jsch)
|
implementation(Dependencies.ThirdParty.jsch)
|
||||||
implementation(Dependencies.ThirdParty.sshj)
|
implementation(Dependencies.ThirdParty.sshj)
|
||||||
implementation(Dependencies.ThirdParty.bouncycastle)
|
implementation(Dependencies.ThirdParty.bouncycastle)
|
||||||
|
|
|
@ -44,7 +44,6 @@ import kotlinx.coroutines.launch
|
||||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi
|
import me.msfjarvis.openpgpktx.util.OpenPgpApi
|
||||||
import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
|
import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
|
||||||
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
|
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
|
||||||
import org.eclipse.jgit.api.Git
|
|
||||||
|
|
||||||
class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
|
class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
|
||||||
|
|
||||||
|
@ -328,8 +327,6 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
|
||||||
if (result.resultCode == RESULT_OK) {
|
if (result.resultCode == RESULT_OK) {
|
||||||
result.data?.getStringArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)?.let { keyIds ->
|
result.data?.getStringArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)?.let { keyIds ->
|
||||||
gpgIdentifierFile.writeText(keyIds.joinToString("\n"))
|
gpgIdentifierFile.writeText(keyIds.joinToString("\n"))
|
||||||
val repo = PasswordRepository.getRepository(null)
|
|
||||||
if (repo != null) {
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
commitChange(
|
commitChange(
|
||||||
getString(
|
getString(
|
||||||
|
@ -338,7 +335,6 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
encrypt(data)
|
encrypt(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,10 +426,6 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
|
||||||
returnIntent.putExtra(RETURN_EXTRA_USERNAME, username)
|
returnIntent.putExtra(RETURN_EXTRA_USERNAME, username)
|
||||||
}
|
}
|
||||||
|
|
||||||
val repo = PasswordRepository.getRepository(null)
|
|
||||||
if (repo != null) {
|
|
||||||
val status = Git(repo).status().call()
|
|
||||||
if (status.modified.isNotEmpty()) {
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
commitChange(
|
commitChange(
|
||||||
getString(
|
getString(
|
||||||
|
@ -442,8 +434,6 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (directoryInputLayout.isVisible && directoryInputLayout.isEnabled && oldFileName != null) {
|
if (directoryInputLayout.isVisible && directoryInputLayout.isEnabled && oldFileName != null) {
|
||||||
val oldFile = File("$repoPath/${oldCategory?.trim('/')}/$oldFileName.gpg")
|
val oldFile = File("$repoPath/${oldCategory?.trim('/')}/$oldFileName.gpg")
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.jgit.api.CommitCommand
|
||||||
import org.eclipse.jgit.api.PullCommand
|
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.transport.RemoteRefUpdate
|
import org.eclipse.jgit.transport.RemoteRefUpdate
|
||||||
import org.eclipse.jgit.transport.SshSessionFactory
|
import org.eclipse.jgit.transport.SshSessionFactory
|
||||||
|
|
||||||
|
@ -43,16 +44,26 @@ class GitCommandExecutor(
|
||||||
message = activity.resources.getString(R.string.git_operation_running),
|
message = activity.resources.getString(R.string.git_operation_running),
|
||||||
length = Snackbar.LENGTH_INDEFINITE,
|
length = Snackbar.LENGTH_INDEFINITE,
|
||||||
)
|
)
|
||||||
|
// Count the number of uncommitted files
|
||||||
|
var nbChanges = 0
|
||||||
var operationResult: Result = Result.Ok
|
var operationResult: Result = Result.Ok
|
||||||
try {
|
try {
|
||||||
for (command in operation.commands) {
|
for (command in operation.commands) {
|
||||||
when (command) {
|
when (command) {
|
||||||
|
is StatusCommand -> {
|
||||||
|
val res = withContext(Dispatchers.IO) {
|
||||||
|
command.call()
|
||||||
|
}
|
||||||
|
nbChanges = res.uncommittedChanges.size
|
||||||
|
}
|
||||||
is CommitCommand -> {
|
is CommitCommand -> {
|
||||||
// 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) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
command.call()
|
command.call()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
is PullCommand -> {
|
is PullCommand -> {
|
||||||
val result = withContext(Dispatchers.IO) {
|
val result = withContext(Dispatchers.IO) {
|
||||||
command.call()
|
command.call()
|
||||||
|
|
|
@ -18,9 +18,14 @@ import org.eclipse.jgit.api.ResetCommand
|
||||||
class ResetToRemoteOperation(fileDir: File, callingActivity: AppCompatActivity) : GitOperation(fileDir, callingActivity) {
|
class ResetToRemoteOperation(fileDir: File, callingActivity: AppCompatActivity) : GitOperation(fileDir, callingActivity) {
|
||||||
|
|
||||||
override val commands = arrayOf(
|
override val commands = arrayOf(
|
||||||
|
// Stage all files
|
||||||
git.add().addFilepattern("."),
|
git.add().addFilepattern("."),
|
||||||
|
// Fetch everything from the origin remote
|
||||||
git.fetch().setRemote("origin"),
|
git.fetch().setRemote("origin"),
|
||||||
|
// Do a hard reset to the remote branch. Equivalent to git reset --hard origin/$remoteBranch
|
||||||
git.reset().setRef("origin/$remoteBranch").setMode(ResetCommand.ResetType.HARD),
|
git.reset().setRef("origin/$remoteBranch").setMode(ResetCommand.ResetType.HARD),
|
||||||
|
// Force-create $remoteBranch if it doesn't exist. This covers the case where you switched
|
||||||
|
// branches from 'master' to anything else.
|
||||||
git.branchCreate().setName(remoteBranch).setForce(true),
|
git.branchCreate().setName(remoteBranch).setForce(true),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,15 @@ import java.io.File
|
||||||
class SyncOperation(fileDir: File, callingActivity: AppCompatActivity) : GitOperation(fileDir, callingActivity) {
|
class SyncOperation(fileDir: File, callingActivity: AppCompatActivity) : GitOperation(fileDir, callingActivity) {
|
||||||
|
|
||||||
override val commands = arrayOf(
|
override val commands = arrayOf(
|
||||||
|
// Stage all files
|
||||||
git.add().addFilepattern("."),
|
git.add().addFilepattern("."),
|
||||||
|
// Populate the changed files count
|
||||||
|
git.status(),
|
||||||
|
// Commit everything! If needed, obviously.
|
||||||
git.commit().setAll(true).setMessage("[Android Password Store] Sync"),
|
git.commit().setAll(true).setMessage("[Android Password Store] Sync"),
|
||||||
|
// Pull and rebase on top of the remote branch
|
||||||
git.pull().setRebase(true).setRemote("origin"),
|
git.pull().setRebase(true).setRemote("origin"),
|
||||||
|
// Push it all back
|
||||||
git.push().setPushAll().setRemote("origin"),
|
git.push().setPushAll().setRemote("origin"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,11 @@ suspend fun FragmentActivity.commitChange(
|
||||||
}
|
}
|
||||||
object : GitOperation(getRepositoryDirectory(), this@commitChange) {
|
object : GitOperation(getRepositoryDirectory(), this@commitChange) {
|
||||||
override val commands = arrayOf(
|
override val commands = arrayOf(
|
||||||
|
// Stage all files
|
||||||
git.add().addFilepattern("."),
|
git.add().addFilepattern("."),
|
||||||
|
// Populate the changed files count
|
||||||
|
git.status(),
|
||||||
|
// Commit everything! If anything changed, that is.
|
||||||
git.commit().setAll(true).setMessage(message),
|
git.commit().setAll(true).setMessage(message),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ object Dependencies {
|
||||||
const val fastscroll = "me.zhanghai.android.fastscroll:library:1.1.4"
|
const val fastscroll = "me.zhanghai.android.fastscroll:library:1.1.4"
|
||||||
const val jsch = "com.jcraft:jsch:0.1.55"
|
const val jsch = "com.jcraft:jsch:0.1.55"
|
||||||
const val jgit = "org.eclipse.jgit:org.eclipse.jgit:3.7.1.201504261725-r"
|
const val jgit = "org.eclipse.jgit:org.eclipse.jgit:3.7.1.201504261725-r"
|
||||||
const val jgit_java7 = "org.eclipse.jgit:org.eclipse.jgit.java7:3.7.1.201504261725-r"
|
|
||||||
const val leakcanary = "com.squareup.leakcanary:leakcanary-android:2.4"
|
const val leakcanary = "com.squareup.leakcanary:leakcanary-android:2.4"
|
||||||
const val plumber = "com.squareup.leakcanary:plumber-android:2.4"
|
const val plumber = "com.squareup.leakcanary:plumber-android:2.4"
|
||||||
const val sshj = "com.hierynomus:sshj:0.29.0"
|
const val sshj = "com.hierynomus:sshj:0.29.0"
|
||||||
|
|
Loading…
Reference in a new issue