@@ -103,8 +103,20 @@ class LandingSession extends Session {
103
103
return command ;
104
104
}
105
105
106
- async suggestAfterPatch ( patch ) {
106
+ async validateLint ( ) {
107
107
const { cli } = this ;
108
+
109
+ const linted = await runAsync ( 'make' , [ 'lint' ] ) ;
110
+ if ( ! linted ) {
111
+ cli . warn ( 'There are lint errors in your patch. ' +
112
+ 'Please fix them before proceeding' ) ;
113
+ return false ;
114
+ }
115
+ }
116
+
117
+ async tryCompleteLanding ( patch ) {
118
+ const { cli } = this ;
119
+
108
120
const subjects = patch . match ( / S u b j e c t : \[ P A T C H .* ?\] .* / g) ;
109
121
if ( ! subjects ) {
110
122
cli . warn ( 'Cannot get number of commits in the patch. ' +
@@ -127,6 +139,7 @@ class LandingSession extends Session {
127
139
if ( ! canFinal ) {
128
140
return ;
129
141
}
142
+
130
143
return this . final ( ) ;
131
144
}
132
145
@@ -140,16 +153,36 @@ class LandingSession extends Session {
140
153
141
154
async apply ( ) {
142
155
const { cli } = this ;
156
+
157
+ // Bail if another landing session is currently in progress.
143
158
if ( ! this . isApplying ( ) ) {
144
- cli . warn ( 'This session can not proceed to apply patches, ' +
145
- 'run `git node land --abort`' ) ;
159
+ cli . warn ( 'Landing session already in progress - ' +
160
+ 'to start a new one run `git node land --abort`' ) ;
146
161
return ;
147
162
}
148
163
await this . tryResetBranch ( ) ;
149
164
150
165
const patch = await this . downloadAndPatch ( ) ;
166
+
167
+ const cleanLint = await this . validateLint ( patch ) ;
168
+ if ( ! cleanLint ) {
169
+ const correctedLint = await cli . prompt ( 'Corrected lint errors?' ) ;
170
+ if ( correctedLint ) {
171
+ await runAsync ( 'git' , [ 'add' , '.' ] ) ;
172
+
173
+ // Final message will be edited later - don't try to change it here.
174
+ await runAsync ( 'git' , [ 'commit' , '--amend' , '--no-edit' ] ) ;
175
+ } else {
176
+ cli . info ( 'Please fix lint errors and then run ' +
177
+ '`git node land --amend` followed by ' +
178
+ '`git node land --continue`.' ) ;
179
+ process . exit ( 1 ) ;
180
+ }
181
+ }
182
+
151
183
this . startAmending ( ) ;
152
- await this . suggestAfterPatch ( patch ) ;
184
+
185
+ await this . tryCompleteLanding ( patch ) ;
153
186
}
154
187
155
188
async amend ( ) {
@@ -212,7 +245,8 @@ class LandingSession extends Session {
212
245
async final ( ) {
213
246
const { cli, owner, repo, upstream, branch, prid } = this ;
214
247
215
- if ( ! this . readyToFinal ( ) ) { // check git rebase/am has been done
248
+ // Check that git rebase/am has been completed.
249
+ if ( ! this . readyToFinal ( ) ) {
216
250
cli . warn ( 'Not yet ready to final' ) ;
217
251
cli . log ( 'A git rebase/am is in progress.' +
218
252
' Please complete it before running git node land --final' ) ;
@@ -274,13 +308,14 @@ class LandingSession extends Session {
274
308
return this . amend ( ) ;
275
309
}
276
310
if ( this . isApplying ( ) ) {
277
- // We are resolving conflict
311
+ // We're still resolving conflicts.
278
312
if ( this . amInProgress ( ) ) {
279
313
cli . log ( 'Looks like you are resolving a `git am` conflict' ) ;
280
314
cli . log ( 'Please run `git status` for help' ) ;
281
- } else { // The conflict has been resolved
315
+ } else {
316
+ // Conflicts has been resolved - amend.
282
317
this . startAmending ( ) ;
283
- return this . suggestAfterPatch ( this . patch ) ;
318
+ return this . tryCompleteLanding ( this . patch ) ;
284
319
}
285
320
return ;
286
321
}
0 commit comments