From a141b0676ee64a405258c8754e5a0f8679b2156a Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Tue, 7 Dec 2021 19:17:18 +0100 Subject: [PATCH] Fixed remote branch checkout Also removed remote branches from "Branches" list in left menu (will add a future "remotes" list) --- .../kotlin/app/extensions/RefExtensions.kt | 22 ++++++++++++++++--- src/main/kotlin/app/git/BranchesManager.kt | 2 -- src/main/kotlin/app/ui/log/Log.kt | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/app/extensions/RefExtensions.kt b/src/main/kotlin/app/extensions/RefExtensions.kt index 5983b4a..4711048 100644 --- a/src/main/kotlin/app/extensions/RefExtensions.kt +++ b/src/main/kotlin/app/extensions/RefExtensions.kt @@ -3,12 +3,28 @@ package app.extensions import org.eclipse.jgit.lib.ObjectIdRef import org.eclipse.jgit.lib.Ref +private const val REMOTE_PREFIX_LENGTH = 3 +private const val LOCAL_PREFIX_LENGTH = 2 + val Ref.simpleName: String get() { - return if (this.isRemote) + 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("/") + } + } + +val Ref.simpleVisibleName: String + get() { + return if (this.isRemote) { name.replace("refs/remotes/", "") - else - this.name.split("/").last() // TODO Do not take the last one, just remove the prefixes + } else { + val split = this.name.split("/") + split.takeLast(split.size - LOCAL_PREFIX_LENGTH).joinToString("/") + } } val Ref.isBranch: Boolean diff --git a/src/main/kotlin/app/git/BranchesManager.kt b/src/main/kotlin/app/git/BranchesManager.kt index 9583b60..df2e4bd 100644 --- a/src/main/kotlin/app/git/BranchesManager.kt +++ b/src/main/kotlin/app/git/BranchesManager.kt @@ -43,7 +43,6 @@ class BranchesManager @Inject constructor() { suspend fun getBranches(git: Git) = withContext(Dispatchers.IO) { return@withContext git .branchList() - .setListMode(ListBranchCommand.ListMode.ALL) .call() } @@ -79,7 +78,6 @@ class BranchesManager @Inject constructor() { .call() } - suspend fun deleteBranch(git: Git, branch: Ref) = withContext(Dispatchers.IO) { git .branchDelete() diff --git a/src/main/kotlin/app/ui/log/Log.kt b/src/main/kotlin/app/ui/log/Log.kt index 8eed9bb..5e1cf1a 100644 --- a/src/main/kotlin/app/ui/log/Log.kt +++ b/src/main/kotlin/app/ui/log/Log.kt @@ -738,7 +738,7 @@ fun RefChip( tint = MaterialTheme.colors.onPrimary, ) Text( - text = ref.simpleName, + text = ref.simpleVisibleName, color = MaterialTheme.colors.onPrimary, fontSize = 12.sp, modifier = Modifier