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
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.ObjectIdRef
import org.eclipse.jgit.lib.Ref
@ -8,22 +9,34 @@ private const val LOCAL_PREFIX_LENGTH = 2
val Ref.simpleName: String
get() {
return if (this.isRemote) {
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("/")
return when {
this.name == Constants.HEAD -> {
this.name
}
this.isRemote -> {
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
get() {
return if (this.isRemote) {
name.replace("refs/remotes/", "")
} else {
val split = this.name.split("/")
split.takeLast(split.size - LOCAL_PREFIX_LENGTH).joinToString("/")
return when {
this.name == Constants.HEAD -> {
this.name
}
this.isRemote -> {
name.replace("refs/remotes/", "")
}
else -> {
val split = this.name.split("/")
split.takeLast(split.size - LOCAL_PREFIX_LENGTH).joinToString("/")
}
}
}