Fixed crash when being detached from any branch

This commit is contained in:
Abdelilah El Aissaoui 2021-12-12 01:07:42 +01:00
parent 0fec32e25f
commit 05326f3a1d

View File

@ -1,5 +1,6 @@
package app.extensions package app.extensions
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.ObjectIdRef import org.eclipse.jgit.lib.ObjectIdRef
import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.Ref
@ -8,22 +9,34 @@ private const val LOCAL_PREFIX_LENGTH = 2
val Ref.simpleName: String val Ref.simpleName: String
get() { get() {
return if (this.isRemote) { return when {
val split = name.split("/") this.name == Constants.HEAD -> {
split.takeLast(split.size - REMOTE_PREFIX_LENGTH).joinToString("/") this.name
} else { }
val split = this.name.split("/") this.isRemote -> {
split.takeLast(split.size - LOCAL_PREFIX_LENGTH).joinToString("/") val split = name.split("/")
split.takeLast(split.size - REMOTE_PREFIX_LENGTH).joinToString("/")
}
else -> {
val split = this.name.split("/")
split.takeLast(split.size - LOCAL_PREFIX_LENGTH).joinToString("/")
}
} }
} }
val Ref.simpleVisibleName: String val Ref.simpleVisibleName: String
get() { get() {
return if (this.isRemote) { return when {
name.replace("refs/remotes/", "") this.name == Constants.HEAD -> {
} else { this.name
val split = this.name.split("/") }
split.takeLast(split.size - LOCAL_PREFIX_LENGTH).joinToString("/") this.isRemote -> {
name.replace("refs/remotes/", "")
}
else -> {
val split = this.name.split("/")
split.takeLast(split.size - LOCAL_PREFIX_LENGTH).joinToString("/")
}
} }
} }