Push deletion is done before doing it locally to prevent deleting the local branch in case of error
This commit is contained in:
parent
857032ec04
commit
9105940e00
@ -85,11 +85,6 @@ class RemoteOperationsManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun deleteBranch(git: Git, ref: Ref) = withContext(Dispatchers.IO) {
|
suspend fun deleteBranch(git: Git, ref: Ref) = withContext(Dispatchers.IO) {
|
||||||
git
|
|
||||||
.branchDelete()
|
|
||||||
.setBranchNames(ref.name)
|
|
||||||
.call()
|
|
||||||
|
|
||||||
val branchSplit = ref.name.split("/").toMutableList()
|
val branchSplit = ref.name.split("/").toMutableList()
|
||||||
val remoteName = branchSplit[2] // Remote name
|
val remoteName = branchSplit[2] // Remote name
|
||||||
repeat(3) {
|
repeat(3) {
|
||||||
@ -101,13 +96,33 @@ class RemoteOperationsManager @Inject constructor(
|
|||||||
val refSpec = RefSpec()
|
val refSpec = RefSpec()
|
||||||
.setSource(null)
|
.setSource(null)
|
||||||
.setDestination(branchName)
|
.setDestination(branchName)
|
||||||
git.push()
|
|
||||||
|
val pushResult = git.push()
|
||||||
.setTransportConfigCallback {
|
.setTransportConfigCallback {
|
||||||
handleTransportCredentials(it)
|
handleTransportCredentials(it)
|
||||||
}
|
}
|
||||||
.setRefSpecs(refSpec)
|
.setRefSpecs(refSpec)
|
||||||
.setRemote(remoteName)
|
.setRemote(remoteName)
|
||||||
.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())
|
||||||
|
}
|
||||||
|
|
||||||
|
git
|
||||||
|
.branchDelete()
|
||||||
|
.setBranchNames(ref.name)
|
||||||
|
.call()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val RemoteRefUpdate.Status.isRejected: Boolean
|
private val RemoteRefUpdate.Status.isRejected: Boolean
|
||||||
|
Loading…
Reference in New Issue
Block a user