-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.gradle
36 lines (33 loc) · 1.16 KB
/
git.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
ext.gitBranch = {
def branchFile = new File(rootProject.projectDir, ".git")
if (branchFile.exists() == false) {
return null
}
def result = "git -C $rootProject.projectDir rev-parse --abbrev-ref HEAD".execute().text.replace('\n', '')
// special case for jenkins pipeline jobs
if (result == null || result != "HEAD") {
return result;
}
def revParseHead = "git -C $rootProject.projectDir rev-parse HEAD".execute().text.replace('\n', '')
def heads = "git -C $rootProject.projectDir ls-remote --heads origin".execute().text
def head = heads.split("\n").findAll { it.startsWith(revParseHead) }[0]
def prefix = "refs/heads/"
println "heads: ---${heads}---"
println "head: ---${head}---"
if (head == null) {
return null
}
return head.substring(head.indexOf(prefix) + prefix.length())
}
ext.hgFeature = {
def featurePrefix = "feature/"
def branch = gitBranch();
if (branch == null) {
return null;
}
if (branch?.startsWith(featurePrefix)) {
def feature = branch.substring(featurePrefix.length()).replaceAll(' ', '_');
return feature;
}
return null;
}