From 9dc5296a6187ceee0920816e177436a21f6210d0 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 17 Feb 2022 23:03:19 +0100 Subject: [PATCH] Return header if no branches match current ref (or null if empty repo) --- src/main/kotlin/app/git/BranchesManager.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/app/git/BranchesManager.kt b/src/main/kotlin/app/git/BranchesManager.kt index 2c47994..b46f5bf 100644 --- a/src/main/kotlin/app/git/BranchesManager.kt +++ b/src/main/kotlin/app/git/BranchesManager.kt @@ -21,7 +21,17 @@ class BranchesManager @Inject constructor() { .repository .fullBranch - return branchList.firstOrNull { it.name == branchName } + var branchFound = branchList.firstOrNull { + it.name == branchName + } + + if(branchFound == null) { + branchFound = branchList.firstOrNull { + it.objectId.name == branchName // Try to get the HEAD + } + } + + return branchFound } suspend fun getBranches(git: Git) = withContext(Dispatchers.IO) {