diff --git a/src/main/kotlin/app/extensions/RefExtensions.kt b/src/main/kotlin/app/extensions/RefExtensions.kt index 59bc815..15c0898 100644 --- a/src/main/kotlin/app/extensions/RefExtensions.kt +++ b/src/main/kotlin/app/extensions/RefExtensions.kt @@ -1,5 +1,6 @@ package app.extensions +import org.eclipse.jgit.lib.ObjectIdRef import org.eclipse.jgit.lib.Ref val Ref.simpleName: String @@ -7,5 +8,13 @@ val Ref.simpleName: String return if (this.name.startsWith("refs/remotes/")) name.replace("refs/remotes/", "") else - this.name.split("/").last() - } \ No newline at end of file + this.name.split("/").last() // TODO Do not take the last one, just remove the prefixes + } + +val Ref.isBranch: Boolean + get() { + return this is ObjectIdRef.PeeledNonTag + } + +val Ref.isTag: Boolean + get() = this is ObjectIdRef.PeeledTag \ No newline at end of file diff --git a/src/main/kotlin/app/git/LogManager.kt b/src/main/kotlin/app/git/LogManager.kt index 48ce02d..88a8a7c 100644 --- a/src/main/kotlin/app/git/LogManager.kt +++ b/src/main/kotlin/app/git/LogManager.kt @@ -1,5 +1,7 @@ package app.git +import app.extensions.isBranch +import app.extensions.simpleName import app.git.graph.GraphCommitList import app.git.graph.GraphWalk import kotlinx.coroutines.Dispatchers @@ -7,6 +9,7 @@ import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.withContext +import org.eclipse.jgit.api.CreateBranchCommand import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.ResetCommand import org.eclipse.jgit.lib.Constants @@ -59,10 +62,15 @@ class LogManager @Inject constructor( } suspend fun checkoutRef(git: Git, ref: Ref) = withContext(Dispatchers.IO) { - git - .checkout() - .setName(ref.name) - .call() + git.checkout().apply { + setName(ref.name) + if(ref.isBranch && ref.name.startsWith("refs/remotes/")) { + setCreateBranch(true) + setName(ref.simpleName) + setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) + } + call() + } } suspend fun revertCommit(git: Git, revCommit: RevCommit) = withContext(Dispatchers.IO) { diff --git a/src/main/kotlin/app/ui/Log.kt b/src/main/kotlin/app/ui/Log.kt index 4381399..a415b80 100644 --- a/src/main/kotlin/app/ui/Log.kt +++ b/src/main/kotlin/app/ui/Log.kt @@ -28,9 +28,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import app.DialogManager -import app.extensions.md5 -import app.extensions.simpleName -import app.extensions.toSmartSystemString +import app.extensions.* import app.git.GitManager import app.git.LogStatus import app.git.ResetType @@ -353,14 +351,14 @@ fun CommitMessage( verticalAlignment = Alignment.CenterVertically, ) { refs.forEach { ref -> - if (ref is ObjectIdRef.PeeledTag) { + if (ref.isTag) { TagChip( ref = ref, onCheckoutTag = { onCheckoutRef(ref) } ) - } else + } else if(ref.isBranch) BranchChip( ref = ref, onCheckoutBranch = {