Skip to content

Commit 3a37d5f

Browse files
committed
change regex to match also grafted branches
1 parent d5182fd commit 3a37d5f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/main/kotlin/io/wusa/GitService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class GitService {
103103

104104
private fun getCurrentBranch(project: Project): String {
105105
val head = GitCommandRunner.execute(project.projectDir, arrayOf("log", "-n", "1", "--pretty=%d", "HEAD"))
106-
return """\(HEAD -> (.*?)[,|)]""".toRegex().find(head)!!.groupValues[1]
106+
return """\([grafted, ]{0,9}HEAD -> (.*?)[,|)]""".toRegex().find(head)!!.groupValues[1]
107107
}
108108
}
109109
}

src/test/kotlin/io/wusa/GitServiceTest.kt

+7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ class GitServiceTest {
174174
Assertions.assertEquals("feature/PascalCase", GitService.currentBranch(project))
175175
}
176176

177+
@Test
178+
fun `issue-65 grafted branch`() {
179+
every { GitCommandRunner.execute(projectDir = any(), args = any()) } returns
180+
"(grafted, HEAD -> release-workflows, origin/release-workflows)"
181+
Assertions.assertEquals("release-workflows", GitService.currentBranch(project))
182+
}
183+
177184
@Test
178185
fun `get current branch with null pointer exception`() {
179186
every { GitCommandRunner.execute(projectDir = any(), args = any()) } throws KotlinNullPointerException()

0 commit comments

Comments
 (0)