From 34759354492ecb4cfe805e5f5ae72c5940554915 Mon Sep 17 00:00:00 2001 From: Andrija Pantovic Date: Wed, 21 Apr 2021 22:29:15 +0200 Subject: [PATCH 1/3] support detached HEAD state improve regex to support detached HEAD state --- src/main/kotlin/io/wusa/GitService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/io/wusa/GitService.kt b/src/main/kotlin/io/wusa/GitService.kt index ed073b2..b11be5f 100644 --- a/src/main/kotlin/io/wusa/GitService.kt +++ b/src/main/kotlin/io/wusa/GitService.kt @@ -103,7 +103,7 @@ class GitService { private fun getCurrentBranch(project: Project): String { val head = GitCommandRunner.execute(project.projectDir, arrayOf("log", "-n", "1", "--pretty=%d", "HEAD")) - return """\([grafted, ]{0,9}HEAD -> (.*?)[,|)]""".toRegex().find(head)!!.groupValues[1] + return """\([grafted, ]{0,9}HEAD -> (.*?)[,|)]|\([grafted, ]{0,9}HEAD,.*origin/(.*?)[,|)]""".toRegex().find(head)!!.groupValues[1] } } } From 6d0270d36d8d1d190b717a0bfc6ee18a0245d10c Mon Sep 17 00:00:00 2001 From: Andrija Pantovic Date: Wed, 21 Apr 2021 23:54:12 +0200 Subject: [PATCH 2/3] fix regex and increase version --- build.gradle.kts | 2 +- src/main/kotlin/io/wusa/GitService.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ca625e0..9a1b7fb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "io.wusa" -version = "2.3.7" +version = "2.3.8" dependencies { implementation(kotlin("stdlib-jdk8")) diff --git a/src/main/kotlin/io/wusa/GitService.kt b/src/main/kotlin/io/wusa/GitService.kt index b11be5f..90a7ae3 100644 --- a/src/main/kotlin/io/wusa/GitService.kt +++ b/src/main/kotlin/io/wusa/GitService.kt @@ -103,7 +103,7 @@ class GitService { private fun getCurrentBranch(project: Project): String { val head = GitCommandRunner.execute(project.projectDir, arrayOf("log", "-n", "1", "--pretty=%d", "HEAD")) - return """\([grafted, ]{0,9}HEAD -> (.*?)[,|)]|\([grafted, ]{0,9}HEAD,.*origin/(.*?)[,|)]""".toRegex().find(head)!!.groupValues[1] + return """\([grafted, ]{0,9}HEAD -> (.*?)[,|)]|\([grafted, ]{0,9}HEAD,.*origin\/(.*?)[,|)]""".toRegex().find(head)!!.groupValues[1] } } } From 82ff85f3063c99541cbf83cb42579866360ef8ff Mon Sep 17 00:00:00 2001 From: Andrija Pantovic Date: Fri, 23 Apr 2021 12:17:26 +0200 Subject: [PATCH 3/3] fix regex and add branch from env var option --- src/main/kotlin/io/wusa/GitService.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/io/wusa/GitService.kt b/src/main/kotlin/io/wusa/GitService.kt index 90a7ae3..121783d 100644 --- a/src/main/kotlin/io/wusa/GitService.kt +++ b/src/main/kotlin/io/wusa/GitService.kt @@ -102,8 +102,12 @@ class GitService { } private fun getCurrentBranch(project: Project): String { - val head = GitCommandRunner.execute(project.projectDir, arrayOf("log", "-n", "1", "--pretty=%d", "HEAD")) - return """\([grafted, ]{0,9}HEAD -> (.*?)[,|)]|\([grafted, ]{0,9}HEAD,.*origin\/(.*?)[,|)]""".toRegex().find(head)!!.groupValues[1] + var branchName: String? = System.getenv("BRANCH_NAME") + if (branchName == null) { + val head = GitCommandRunner.execute(project.projectDir, arrayOf("log", "-n", "1", "--pretty=%d", "HEAD")) + branchName = """\([grafted, ]{0,9}HEAD(?: -> |,)(?:(\S+),|\)|.*,(?: origin\/| )(\S+)\))""".toRegex().find(head)!!.groupValues.filter { it != "" }[1] + } + return branchName } } }