@@ -24,6 +24,8 @@ class GitAdapter extends BaseScmAdapter {
24
24
private static final String AHEAD = ' ahead'
25
25
private static final String BEHIND = ' behind'
26
26
27
+ private File workingDirectory
28
+
27
29
class GitConfig {
28
30
String requireBranch = ' master'
29
31
def pushToRemote = ' origin' // needs to be def as can be boolean or string
@@ -59,6 +61,7 @@ class GitAdapter extends BaseScmAdapter {
59
61
return directory. parentFile? isSupported(directory. parentFile) : false
60
62
}
61
63
64
+ workingDirectory = directory
62
65
true
63
66
}
64
67
@@ -89,7 +92,7 @@ class GitAdapter extends BaseScmAdapter {
89
92
90
93
@Override
91
94
void checkUpdateNeeded () {
92
- exec([' git' , ' remote' , ' update' ], errorPatterns : [' error: ' , ' fatal: ' ])
95
+ exec([' git' , ' remote' , ' update' ], directory : workingDirectory, errorPatterns : [' error: ' , ' fatal: ' ])
93
96
94
97
def status = gitRemoteStatus()
95
98
@@ -105,9 +108,9 @@ class GitAdapter extends BaseScmAdapter {
105
108
@Override
106
109
void createReleaseTag (String message ) {
107
110
def tagName = tagName()
108
- exec([' git' , ' tag' , ' -a' , tagName, ' -m' , message], errorMessage : " Duplicate tag [$tagName ]" , errorPatterns : [' already exists' ])
111
+ exec([' git' , ' tag' , ' -a' , tagName, ' -m' , message], directory : workingDirectory, errorMessage : " Duplicate tag [$tagName ]" , errorPatterns : [' already exists' ])
109
112
if (shouldPush()) {
110
- exec([' git' , ' push' , ' --porcelain' , extension. git. pushToRemote, tagName] + extension. git. pushOptions, errorMessage : " Failed to push tag [$tagName ] to remote" , errorPatterns : [' [rejected]' , ' error: ' , ' fatal: ' ])
113
+ exec([' git' , ' push' , ' --porcelain' , extension. git. pushToRemote, tagName] + extension. git. pushOptions, directory : workingDirectory, errorMessage : " Failed to push tag [$tagName ] to remote" , errorPatterns : [' [rejected]' , ' error: ' , ' fatal: ' ])
111
114
}
112
115
}
113
116
@@ -120,31 +123,31 @@ class GitAdapter extends BaseScmAdapter {
120
123
command << ' -a'
121
124
}
122
125
123
- exec(command, errorPatterns : [' error: ' , ' fatal: ' ])
126
+ exec(command, directory : workingDirectory, errorPatterns : [' error: ' , ' fatal: ' ])
124
127
125
128
if (shouldPush()) {
126
129
def branch = gitCurrentBranch()
127
130
if (extension. git. pushToBranchPrefix) {
128
131
branch = " HEAD:${ extension.git.pushToBranchPrefix}${ branch} "
129
132
}
130
- exec([' git' , ' push' , ' --porcelain' , extension. git. pushToRemote, branch] + extension. git. pushOptions, errorMessage : ' Failed to push to remote' , errorPatterns : [' [rejected]' , ' error: ' , ' fatal: ' ])
133
+ exec([' git' , ' push' , ' --porcelain' , extension. git. pushToRemote, branch] + extension. git. pushOptions, directory : workingDirectory, errorMessage : ' Failed to push to remote' , errorPatterns : [' [rejected]' , ' error: ' , ' fatal: ' ])
131
134
}
132
135
}
133
136
134
137
@Override
135
138
void add (File file ) {
136
- exec([' git' , ' add' , file. path], errorMessage : " Error adding file ${ file.name} " , errorPatterns : [' error: ' , ' fatal: ' ])
139
+ exec([' git' , ' add' , file. path], directory : workingDirectory, errorMessage : " Error adding file ${ file.name} " , errorPatterns : [' error: ' , ' fatal: ' ])
137
140
}
138
141
139
142
@Override
140
143
void revert () {
141
- exec([' git' , ' checkout' , findPropertiesFile(). name], errorMessage : ' Error reverting changes made by the release plugin.' )
144
+ exec([' git' , ' checkout' , findPropertiesFile(). name], directory : workingDirectory, errorMessage : ' Error reverting changes made by the release plugin.' )
142
145
}
143
146
144
147
private boolean shouldPush () {
145
148
def shouldPush = false
146
149
if (extension. git. pushToRemote) {
147
- exec([' git' , ' remote' ]). eachLine { line ->
150
+ exec([' git' , ' remote' ], directory : workingDirectory ). eachLine { line ->
148
151
Matcher matcher = line =~ ~/ ^\s *(.*)\s *$/
149
152
if (matcher. matches() && matcher. group(1 ) == extension. git. pushToRemote) {
150
153
shouldPush = true
@@ -159,12 +162,12 @@ class GitAdapter extends BaseScmAdapter {
159
162
}
160
163
161
164
private String gitCurrentBranch () {
162
- def matches = exec([' git' , ' branch' , ' --no-color' ]). readLines(). grep(~/ \s *\* .*/ )
165
+ def matches = exec([' git' , ' branch' , ' --no-color' ], directory : workingDirectory ). readLines(). grep(~/ \s *\* .*/ )
163
166
matches[0 ]. trim() - (~/ ^\*\s +/ )
164
167
}
165
168
166
169
private Map<String , List<String > > gitStatus () {
167
- exec([' git' , ' status' , ' --porcelain' ]). readLines(). groupBy {
170
+ exec([' git' , ' status' , ' --porcelain' ], directory : workingDirectory ). readLines(). groupBy {
168
171
if (it ==~ / ^\s *\? {2}.*/ ) {
169
172
UNVERSIONED
170
173
} else {
@@ -174,7 +177,7 @@ class GitAdapter extends BaseScmAdapter {
174
177
}
175
178
176
179
private Map<String , Integer > gitRemoteStatus () {
177
- def branchStatus = exec([' git' , ' status' , ' --porcelain' , ' -b' ]). readLines()[0 ]
180
+ def branchStatus = exec([' git' , ' status' , ' --porcelain' , ' -b' ], directory : workingDirectory ). readLines()[0 ]
178
181
def aheadMatcher = branchStatus =~ / .*ahead (\d +).*/
179
182
def behindMatcher = branchStatus =~ / .*behind (\d +).*/
180
183
0 commit comments