Added error display when a push has failed
This commit is contained in:
parent
3ed5f0cc1e
commit
908696735b
@ -207,8 +207,11 @@ class GitManager @Inject constructor(
|
|||||||
|
|
||||||
fun push() = managerScope.launch {
|
fun push() = managerScope.launch {
|
||||||
safeProcessing {
|
safeProcessing {
|
||||||
remoteOperationsManager.push(safeGit)
|
try {
|
||||||
coLoadLog()
|
remoteOperationsManager.push(safeGit)
|
||||||
|
} finally {
|
||||||
|
coLoadLog()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,10 +9,7 @@ import kotlinx.coroutines.isActive
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.ProgressMonitor
|
import org.eclipse.jgit.lib.ProgressMonitor
|
||||||
import org.eclipse.jgit.transport.CredentialsProvider
|
import org.eclipse.jgit.transport.*
|
||||||
import org.eclipse.jgit.transport.HttpTransport
|
|
||||||
import org.eclipse.jgit.transport.RefSpec
|
|
||||||
import org.eclipse.jgit.transport.SshTransport
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -40,7 +37,7 @@ class RemoteOperationsManager @Inject constructor(
|
|||||||
suspend fun push(git: Git) = withContext(Dispatchers.IO) {
|
suspend fun push(git: Git) = withContext(Dispatchers.IO) {
|
||||||
val currentBranchRefSpec = git.repository.fullBranch
|
val currentBranchRefSpec = git.repository.fullBranch
|
||||||
|
|
||||||
git
|
val pushResult = git
|
||||||
.push()
|
.push()
|
||||||
.setRefSpecs(RefSpec(currentBranchRefSpec))
|
.setRefSpecs(RefSpec(currentBranchRefSpec))
|
||||||
.setPushTags()
|
.setPushTags()
|
||||||
@ -52,8 +49,43 @@ class RemoteOperationsManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
|
val results =
|
||||||
|
pushResult.map { it.remoteUpdates.filter { remoteRefUpdate -> remoteRefUpdate.status.isRejected } }
|
||||||
|
.flatten()
|
||||||
|
if (results.isNotEmpty()) {
|
||||||
|
val error = StringBuilder()
|
||||||
|
|
||||||
|
results.forEach { result ->
|
||||||
|
error.append(result.statusMessage)
|
||||||
|
error.append("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
throw Exception(error.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val RemoteRefUpdate.Status.isRejected: Boolean
|
||||||
|
get() {
|
||||||
|
return this == RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD ||
|
||||||
|
this == RemoteRefUpdate.Status.REJECTED_NODELETE ||
|
||||||
|
this == RemoteRefUpdate.Status.REJECTED_REMOTE_CHANGED ||
|
||||||
|
this == RemoteRefUpdate.Status.REJECTED_OTHER_REASON
|
||||||
|
}
|
||||||
|
|
||||||
|
private val RemoteRefUpdate.statusMessage: String
|
||||||
|
get() {
|
||||||
|
return when (this.status) {
|
||||||
|
RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD -> "Failed to push some refs to ${this.remoteName}. " +
|
||||||
|
"Updates were rejected because the remote contains work that you do not have locally. Pulling changes from remote may help."
|
||||||
|
RemoteRefUpdate.Status.REJECTED_NODELETE -> "Could not delete ref because the remote doesn't support deleting refs."
|
||||||
|
RemoteRefUpdate.Status.REJECTED_REMOTE_CHANGED -> "Ref rejected, old object id in remote has changed."
|
||||||
|
RemoteRefUpdate.Status.REJECTED_OTHER_REASON -> this.message ?: "Push rejected for unknown reasons."
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun clone(directory: File, url: String) = withContext(Dispatchers.IO) {
|
suspend fun clone(directory: File, url: String) = withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
_cloneStatus.value = CloneStatus.Cloning(0)
|
_cloneStatus.value = CloneStatus.Cloning(0)
|
||||||
|
@ -65,7 +65,7 @@ class StatusManager @Inject constructor(
|
|||||||
val entries = it.value
|
val entries = it.value
|
||||||
|
|
||||||
if(entries.count() > 1)
|
if(entries.count() > 1)
|
||||||
entries.filter { it.oldPath != "/dev/null" }
|
entries.filter { entry -> entry.oldPath != "/dev/null" }
|
||||||
else
|
else
|
||||||
entries
|
entries
|
||||||
}.flatten()
|
}.flatten()
|
||||||
@ -80,7 +80,7 @@ class StatusManager @Inject constructor(
|
|||||||
val entries = it.value
|
val entries = it.value
|
||||||
|
|
||||||
if(entries.count() > 1)
|
if(entries.count() > 1)
|
||||||
entries.filter { it.newPath != "/dev/null" }
|
entries.filter { entry -> entry.newPath != "/dev/null" }
|
||||||
else
|
else
|
||||||
entries
|
entries
|
||||||
}.flatten()
|
}.flatten()
|
||||||
|
@ -148,6 +148,7 @@ fun AppTab(
|
|||||||
text = safeLastError.message,
|
text = safeLastError.message,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(top = 8.dp, bottom = 16.dp)
|
.padding(top = 8.dp, bottom = 16.dp)
|
||||||
|
.widthIn(max = 600.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user