This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
forked from pngowda/xtext-build-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_functions.groovy
116 lines (97 loc) · 2.48 KB
/
git_functions.groovy
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def createBranch(branch) {
def rc = sh (script: "git checkout -b ${branch}", returnStatus: true)
return rc == 0
}
def boolean branchExists(branch) {
def rc = sh (script: "git rev-parse --verify ${branch}", returnStatus: true)
return rc == 0
}
def boolean deleteBranch(branch) {
def rc = sh (script: "git branch -D ${branch}", returnStatus: true)
return rc == 0
}
def boolean pull(branch, remote='origin') {
def rc = sh (script: "git pull ${remote} ${branch}", returnStatus: true)
return rc == 0
}
def commit(message, gitName='genie.xtext', gitEmail='xtext-github@eclipse.org') {
def git_cmd
print sh(
script: 'git add -A',
returnStdout: true
)
// return status, but ignore
sh(
script: "git commit -a -m '${message}\n\nSigned-off-by: ${gitName} <${gitEmail}>'",
returnStatus: true
)
print sh(
script: "git show --name-only HEAD",
returnStdout: true
)
return git_cmd
}
def void printChanges() {
git_changes = sh (
script: 'git show --name-only HEAD',
returnStdout: true
).trim()
print git_changes
}
def getGitRemote(name = '', type = 'fetch') {
dir("workDir") {
gitRemote = sh (
script: "git remote -v | grep '${name}' | grep ${type} | awk '{print \$2}' | head -1",
returnStdout: true
).trim()
}
return gitRemote
}
def tag(tagName) {
def git_cmd
git_cmd = sh (
script: "git tag --force -a ${tagName} -m 'release ${tagName}'",
returnStdout: true
).trim()
return git_cmd
}
def push(branch, openPR=false) {
def rc = sh (
script: "git push --force --tags origin ${branch}",
returnStatus: true
)
/*
if (rc == 0 && openPR) {
def message = sh (script: "git log -1 --pretty='format:%s'", returnStdout: true)
sh(
script: "hub pull-request -m '**** TEST TEST ${message}'",
returnStatus: true
)
}
*/
return rc
}
def getGitCommit() {
git_commit = sh (
script: 'git rev-parse HEAD',
returnStdout: true
).trim()
return git_commit
}
def resetHard() {
def git_cmd
git_cmd = sh (
script: 'git reset --hard',
returnStdout: true
).trim()
return git_cmd
}
def checkoutBranch(branchName) {
def git_cmd
git_cmd = sh (
script: "git checkout ${branchName}",
returnStdout: true
).trim()
return git_cmd
}
return this