Skip to content

Commit 82ff85f

Browse files
author
Andrija Pantovic
committedApr 23, 2021
fix regex and add branch from env var option
1 parent 6d0270d commit 82ff85f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ class GitService {
102102
}
103103

104104
private fun getCurrentBranch(project: Project): String {
105-
val head = GitCommandRunner.execute(project.projectDir, arrayOf("log", "-n", "1", "--pretty=%d", "HEAD"))
106-
return """\([grafted, ]{0,9}HEAD -> (.*?)[,|)]|\([grafted, ]{0,9}HEAD,.*origin\/(.*?)[,|)]""".toRegex().find(head)!!.groupValues[1]
105+
var branchName: String? = System.getenv("BRANCH_NAME")
106+
if (branchName == null) {
107+
val head = GitCommandRunner.execute(project.projectDir, arrayOf("log", "-n", "1", "--pretty=%d", "HEAD"))
108+
branchName = """\([grafted, ]{0,9}HEAD(?: -> |,)(?:(\S+),|\)|.*,(?: origin\/| )(\S+)\))""".toRegex().find(head)!!.groupValues.filter { it != "" }[1]
109+
}
110+
return branchName
107111
}
108112
}
109113
}

0 commit comments

Comments
 (0)
Please sign in to comment.