11'use strict' ;
22
33const path = require ( 'path' ) ;
4+ const os = require ( 'os' ) ;
45const {
56 getUnmarkedDeprecations,
67 updateDeprecations
@@ -130,8 +131,19 @@ class LandingSession extends Session {
130131 return command ;
131132 }
132133
133- async suggestAfterPatch ( patch ) {
134+ async validateLint ( ) {
135+ // The linter is currently only run on non-Windows platforms.
136+ if ( os . platform ( ) === 'win32' ) {
137+ return true ;
138+ }
139+
140+ const linted = await runAsync ( 'make' , [ 'lint' ] ) ;
141+ return linted ;
142+ }
143+
144+ async tryCompleteLanding ( patch ) {
134145 const { cli } = this ;
146+
135147 const subjects = patch . match ( / S u b j e c t : \[ P A T C H .* ?\] .* / g) ;
136148 if ( ! subjects ) {
137149 cli . warn ( 'Cannot get number of commits in the patch. ' +
@@ -154,6 +166,7 @@ class LandingSession extends Session {
154166 if ( ! canFinal ) {
155167 return ;
156168 }
169+
157170 return this . final ( ) ;
158171 }
159172
@@ -167,16 +180,47 @@ class LandingSession extends Session {
167180
168181 async apply ( ) {
169182 const { cli } = this ;
183+
184+ // Bail if another landing session is currently in progress.
170185 if ( ! this . isApplying ( ) ) {
171- cli . warn ( 'This session can not proceed to apply patches, ' +
172- 'run `git node land --abort`' ) ;
186+ cli . warn ( 'Landing session already in progress - ' +
187+ 'to start a new one run `git node land --abort`' ) ;
173188 return ;
174189 }
175190 await this . tryResetBranch ( ) ;
176191
177192 const patch = await this . downloadAndPatch ( ) ;
193+
194+ const cleanLint = await this . validateLint ( ) ;
195+ if ( ! cleanLint ) {
196+ const tryFixLint = await cli . prompt (
197+ 'Lint failed - try fixing with \'make lint-js-fix\'?' ) ;
198+ if ( tryFixLint ) {
199+ await runAsync ( 'make' , [ 'lint-js-fix' ] ) ;
200+ const fixed = await this . validateLint ( ) ;
201+ if ( ! fixed ) {
202+ cli . warn ( 'Patch still contains lint errors. ' +
203+ 'Please fix manually before proceeding' ) ;
204+ }
205+ }
206+
207+ const correctedLint = await cli . prompt ( 'Corrected all lint errors?' ) ;
208+ if ( correctedLint ) {
209+ await runAsync ( 'git' , [ 'add' , '.' ] ) ;
210+
211+ // Final message will be edited later - don't try to change it here.
212+ await runAsync ( 'git' , [ 'commit' , '--amend' , '--no-edit' ] ) ;
213+ } else {
214+ cli . info ( 'Please fix lint errors and then run ' +
215+ '`git node land --amend` followed by ' +
216+ '`git node land --continue`.' ) ;
217+ process . exit ( 1 ) ;
218+ }
219+ }
220+
178221 this . startAmending ( ) ;
179- await this . suggestAfterPatch ( patch ) ;
222+
223+ await this . tryCompleteLanding ( patch ) ;
180224 }
181225
182226 async amend ( ) {
@@ -239,7 +283,8 @@ class LandingSession extends Session {
239283 async final ( ) {
240284 const { cli, owner, repo, upstream, branch, prid } = this ;
241285
242- if ( ! this . readyToFinal ( ) ) { // check git rebase/am has been done
286+ // Check that git rebase/am has been completed.
287+ if ( ! this . readyToFinal ( ) ) {
243288 cli . warn ( 'Not yet ready to final' ) ;
244289 cli . log ( 'A git rebase/am is in progress.' +
245290 ' Please complete it before running git node land --final' ) ;
@@ -301,13 +346,14 @@ class LandingSession extends Session {
301346 return this . amend ( ) ;
302347 }
303348 if ( this . isApplying ( ) ) {
304- // We are resolving conflict
349+ // We're still resolving conflicts.
305350 if ( this . amInProgress ( ) ) {
306351 cli . log ( 'Looks like you are resolving a `git am` conflict' ) ;
307352 cli . log ( 'Please run `git status` for help' ) ;
308- } else { // The conflict has been resolved
353+ } else {
354+ // Conflicts has been resolved - amend.
309355 this . startAmending ( ) ;
310- return this . suggestAfterPatch ( this . patch ) ;
356+ return this . tryCompleteLanding ( this . patch ) ;
311357 }
312358 return ;
313359 }
0 commit comments