@@ -17,105 +17,105 @@ import java.util.regex.Matcher
17
17
18
18
class GitAdapter extends BaseScmAdapter {
19
19
20
- private static final String LINE = ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
21
-
22
- private static final String UNCOMMITTED = ' uncommitted'
23
- private static final String UNVERSIONED = ' unversioned'
24
- private static final String AHEAD = ' ahead'
25
- private static final String BEHIND = ' behind'
26
-
27
- class GitConfig {
28
- String requireBranch = ' master'
29
- def pushToRemote = ' origin' // needs to be def as can be boolean or string
30
- boolean pushToCurrentBranch = false
31
- }
32
-
33
- GitAdapter (Project project ) {
34
- super (project)
35
- }
36
-
37
- @Override
38
- Object createNewConfig () {
39
- return new GitConfig ()
40
- }
41
-
42
- @Override
43
- boolean isSupported (File directory ) {
44
- if (! directory. list(). grep(' .git' )) {
45
- return directory. parentFile? isSupported(directory. parentFile) : false
46
- }
47
-
48
- true
49
- }
50
-
51
- @Override
52
- void init () {
53
- if (extension. git. requireBranch) {
54
- def branch = gitCurrentBranch()
55
- if (branch != extension. git. requireBranch) {
56
- throw new GradleException (" Current Git branch is \" $branch \" and not \" ${ extension.git.requireBranch } \" ." )
57
- }
58
- }
59
- }
60
-
61
- @Override
62
- void checkCommitNeeded () {
63
-
64
- def status = gitStatus()
65
-
66
- if (status[UNVERSIONED ]) {
67
- warnOrThrow(extension. failOnUnversionedFiles,
68
- ([' You have unversioned files:' , LINE , * status[UNVERSIONED ], LINE ] as String []). join(' \n ' ))
69
- }
70
-
71
- if (status[UNCOMMITTED ]) {
72
- warnOrThrow(extension. failOnCommitNeeded,
73
- ([' You have uncommitted files:' , LINE , * status[UNCOMMITTED ], LINE ] as String []). join(' \n ' ))
74
- }
75
- }
76
-
77
- @Override
78
- void checkUpdateNeeded () {
79
- exec([' git' , ' remote' , ' update' ], errorPatterns : [' error: ' , ' fatal: ' ])
80
-
81
- def status = gitRemoteStatus()
82
-
83
- if (status[AHEAD ]) {
84
- warnOrThrow(extension. failOnPublishNeeded, " You have ${ status[AHEAD]} local change(s) to push." )
85
- }
86
-
87
- if (status[BEHIND ]) {
88
- warnOrThrow(extension. failOnUpdateNeeded, " You have ${ status[BEHIND]} remote change(s) to pull." )
89
- }
90
- }
91
-
92
- @Override
93
- void createReleaseTag (String message ) {
94
- def tagName = tagName()
95
- exec([' git' , ' tag' , ' -a' , tagName, ' -m' , message], errorMessage : " Duplicate tag [$tagName ]" , errorPatterns : [' already exists' ])
20
+ private static final String LINE = ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
21
+
22
+ private static final String UNCOMMITTED = ' uncommitted'
23
+ private static final String UNVERSIONED = ' unversioned'
24
+ private static final String AHEAD = ' ahead'
25
+ private static final String BEHIND = ' behind'
26
+
27
+ class GitConfig {
28
+ String requireBranch = ' master'
29
+ def pushToRemote = ' origin' // needs to be def as can be boolean or string
30
+ boolean pushToCurrentBranch = false
31
+ }
32
+
33
+ GitAdapter (Project project ) {
34
+ super (project)
35
+ }
36
+
37
+ @Override
38
+ Object createNewConfig () {
39
+ return new GitConfig ()
40
+ }
41
+
42
+ @Override
43
+ boolean isSupported (File directory ) {
44
+ if (! directory. list(). grep(' .git' )) {
45
+ return directory. parentFile? isSupported(directory. parentFile) : false
46
+ }
47
+
48
+ true
49
+ }
50
+
51
+ @Override
52
+ void init () {
53
+ if (extension. git. requireBranch) {
54
+ def branch = gitCurrentBranch()
55
+ if (branch != extension. git. requireBranch) {
56
+ throw new GradleException (" Current Git branch is \" $branch \" and not \" ${ extension.git.requireBranch } \" ." )
57
+ }
58
+ }
59
+ }
60
+
61
+ @Override
62
+ void checkCommitNeeded () {
63
+
64
+ def status = gitStatus()
65
+
66
+ if (status[UNVERSIONED ]) {
67
+ warnOrThrow(extension. failOnUnversionedFiles,
68
+ ([' You have unversioned files:' , LINE , * status[UNVERSIONED ], LINE ] as String []). join(' \n ' ))
69
+ }
70
+
71
+ if (status[UNCOMMITTED ]) {
72
+ warnOrThrow(extension. failOnCommitNeeded,
73
+ ([' You have uncommitted files:' , LINE , * status[UNCOMMITTED ], LINE ] as String []). join(' \n ' ))
74
+ }
75
+ }
76
+
77
+ @Override
78
+ void checkUpdateNeeded () {
79
+ exec([' git' , ' remote' , ' update' ], errorPatterns : [' error: ' , ' fatal: ' ])
80
+
81
+ def status = gitRemoteStatus()
82
+
83
+ if (status[AHEAD ]) {
84
+ warnOrThrow(extension. failOnPublishNeeded, " You have ${ status[AHEAD]} local change(s) to push." )
85
+ }
86
+
87
+ if (status[BEHIND ]) {
88
+ warnOrThrow(extension. failOnUpdateNeeded, " You have ${ status[BEHIND]} remote change(s) to pull." )
89
+ }
90
+ }
91
+
92
+ @Override
93
+ void createReleaseTag (String message ) {
94
+ def tagName = tagName()
95
+ exec([' git' , ' tag' , ' -a' , tagName, ' -m' , message], errorMessage : " Duplicate tag [$tagName ]" , errorPatterns : [' already exists' ])
96
96
if (shouldPush()) {
97
97
exec([' git' , ' push' , ' --porcelain' , ' origin' , tagName], errorMessage : " Failed to push tag [$tagName ] to remote" , errorPatterns : [' [rejected]' , ' error: ' , ' fatal: ' ])
98
98
}
99
- }
99
+ }
100
100
101
- @Override
102
- void commit (String message ) {
103
- exec([' git' , ' commit' , ' -a' , ' -m' , message])
101
+ @Override
102
+ void commit (String message ) {
103
+ exec([' git' , ' commit' , ' -a' , ' -m' , message])
104
104
if (shouldPush()) {
105
105
def branch
106
106
if (extension. git. pushToCurrentBranch) {
107
107
branch = gitCurrentBranch()
108
108
} else {
109
- branch = extension. git. requireBranch ? extension. git. requireBranch : ' master'
109
+ branch = extension. git. requireBranch ? extension. git. requireBranch : ' master'
110
110
}
111
111
exec([' git' , ' push' , ' --porcelain' , extension. git. pushToRemote, branch], errorMessage : ' Failed to push to remote' , errorPatterns : [' [rejected]' , ' error: ' , ' fatal: ' ])
112
112
}
113
- }
113
+ }
114
114
115
- @Override
116
- void revert () {
117
- exec([' git' , ' checkout' , findPropertiesFile(). name], errorMessage : ' Error reverting changes made by the release plugin.' )
118
- }
115
+ @Override
116
+ void revert () {
117
+ exec([' git' , ' checkout' , findPropertiesFile(). name], errorMessage : ' Error reverting changes made by the release plugin.' )
118
+ }
119
119
120
120
private boolean shouldPush () {
121
121
def shouldPush = false
@@ -134,34 +134,34 @@ class GitAdapter extends BaseScmAdapter {
134
134
shouldPush
135
135
}
136
136
137
- private String gitCurrentBranch () {
138
- def matches = exec([' git' , ' branch' ]). readLines(). grep(~/ \s *\* .*/ )
139
- matches[0 ]. trim() - (~/ ^\*\s +/ )
140
- }
141
-
142
- private Map<String , List<String > > gitStatus () {
143
- exec([' git' , ' status' , ' --porcelain' ]). readLines(). groupBy {
144
- if (it ==~ / ^\s *\? {2}.*/ ) {
145
- UNVERSIONED
146
- } else {
147
- UNCOMMITTED
148
- }
149
- }
150
- }
151
-
152
- private Map<String , Integer > gitRemoteStatus () {
153
- def branchStatus = exec([' git' , ' status' , ' -sb' ]). readLines()[0 ]
154
- def aheadMatcher = branchStatus =~ / .*ahead (\d +).*/
155
- def behindMatcher = branchStatus =~ / .*behind (\d +).*/
156
-
157
- def remoteStatus = [:]
158
-
159
- if (aheadMatcher. matches()) {
160
- remoteStatus[AHEAD ] = aheadMatcher[0 ][1 ]
161
- }
162
- if (behindMatcher. matches()) {
163
- remoteStatus[BEHIND ] = behindMatcher[0 ][1 ]
164
- }
165
- remoteStatus
166
- }
137
+ private String gitCurrentBranch () {
138
+ def matches = exec([' git' , ' branch' ]). readLines(). grep(~/ \s *\* .*/ )
139
+ matches[0 ]. trim() - (~/ ^\*\s +/ )
140
+ }
141
+
142
+ private Map<String , List<String > > gitStatus () {
143
+ exec([' git' , ' status' , ' --porcelain' ]). readLines(). groupBy {
144
+ if (it ==~ / ^\s *\? {2}.*/ ) {
145
+ UNVERSIONED
146
+ } else {
147
+ UNCOMMITTED
148
+ }
149
+ }
150
+ }
151
+
152
+ private Map<String , Integer > gitRemoteStatus () {
153
+ def branchStatus = exec([' git' , ' status' , ' -sb' ]). readLines()[0 ]
154
+ def aheadMatcher = branchStatus =~ / .*ahead (\d +).*/
155
+ def behindMatcher = branchStatus =~ / .*behind (\d +).*/
156
+
157
+ def remoteStatus = [:]
158
+
159
+ if (aheadMatcher. matches()) {
160
+ remoteStatus[AHEAD ] = aheadMatcher[0 ][1 ]
161
+ }
162
+ if (behindMatcher. matches()) {
163
+ remoteStatus[BEHIND ] = behindMatcher[0 ][1 ]
164
+ }
165
+ remoteStatus
166
+ }
167
167
}
0 commit comments