1
1
'use strict' ;
2
2
3
3
const {
4
- runAsync, runSync, forceRunAsync
4
+ runAsync, runSync, forceRunAsync, exit
5
5
} = require ( './run' ) ;
6
6
const Session = require ( './session' ) ;
7
7
@@ -31,7 +31,7 @@ class LandingSession extends Session {
31
31
const { cli } = this ;
32
32
this . cleanFiles ( ) ;
33
33
await this . tryResetBranch ( ) ;
34
- cli . log ( `Aborted \`git node land\` session in ${ this . ncuDir } ` ) ;
34
+ cli . ok ( `Aborted \`git node land\` session in ${ this . ncuDir } ` ) ;
35
35
}
36
36
37
37
async apply ( ) {
@@ -51,9 +51,28 @@ class LandingSession extends Session {
51
51
} ) ;
52
52
this . savePatch ( patch ) ;
53
53
cli . stopSpinner ( `Downloaded patch to ${ this . patchPath } ` ) ;
54
-
54
+ cli . separator ( ) ;
55
55
// TODO: check that patches downloaded match metadata.commits
56
- await runAsync ( 'git' , [ 'am' , '--whitespace=fix' , this . patchPath ] ) ;
56
+ try {
57
+ await forceRunAsync ( 'git' , [ 'am' , '--whitespace=fix' , this . patchPath ] , {
58
+ ignoreFailure : false
59
+ } ) ;
60
+ } catch ( ex ) {
61
+ const should3Way = await cli . prompt (
62
+ 'The normal `git am` failed. Do you want to retry with 3-way merge?' ) ;
63
+ if ( should3Way ) {
64
+ await forceRunAsync ( 'git' , [ 'am' , '--abort' ] ) ;
65
+ await runAsync ( 'git' , [
66
+ 'am' ,
67
+ '-3' ,
68
+ '--whitespace=fix' ,
69
+ this . patchPath
70
+ ] ) ;
71
+ } else {
72
+ cli . error ( 'Failed to apply patches' ) ;
73
+ exit ( ) ;
74
+ }
75
+ }
57
76
cli . ok ( 'Patches applied' ) ;
58
77
59
78
this . startAmending ( ) ;
@@ -117,7 +136,6 @@ class LandingSession extends Session {
117
136
const messageFile = this . saveMessage ( rev , message ) ;
118
137
cli . separator ( 'New Message' ) ;
119
138
cli . log ( message . trim ( ) ) ;
120
- cli . separator ( ) ;
121
139
const takeMessage = await cli . prompt ( 'Use this message?' ) ;
122
140
if ( takeMessage ) {
123
141
await runAsync ( 'git' , [ 'commit' , '--amend' , '-F' , messageFile ] ) ;
@@ -142,12 +160,22 @@ class LandingSession extends Session {
142
160
const notYetPushed = this . getNotYetPushedCommits ( ) ;
143
161
const notYetPushedVerbose = this . getNotYetPushedCommits ( true ) ;
144
162
await runAsync ( 'core-validate-commit' , notYetPushed ) ;
163
+
145
164
cli . separator ( ) ;
146
165
cli . log ( 'The following commits are ready to be pushed to ' +
147
166
`${ upstream } /${ branch } ` ) ;
148
167
cli . log ( `- ${ notYetPushedVerbose . join ( '\n- ' ) } ` ) ;
149
168
cli . separator ( ) ;
150
- cli . log ( `run \`git push ${ upstream } ${ branch } \` to finish landing` ) ;
169
+
170
+ let willBeLanded = notYetPushed [ notYetPushed . length - 1 ] . slice ( 0 , 7 ) ;
171
+ if ( notYetPushed . length > 1 ) {
172
+ const head = this . getUpstreamHead ( ) . slice ( 0 , 7 ) ;
173
+ willBeLanded = `${ head } ...${ willBeLanded } ` ;
174
+ }
175
+ cli . log ( 'To finish landing:' ) ;
176
+ cli . log ( `1. Run \`git push ${ upstream } ${ branch } \`` ) ;
177
+ cli . log ( `2. Post in the PR: \`Landed in ${ willBeLanded } \`` ) ;
178
+
151
179
const shouldClean = await cli . prompt ( 'Clean up generated temporary files?' ) ;
152
180
if ( shouldClean ) {
153
181
this . cleanFiles ( ) ;
@@ -183,11 +211,17 @@ class LandingSession extends Session {
183
211
getNotYetPushedCommits ( verbose ) {
184
212
const { upstream, branch } = this ;
185
213
const ref = `${ upstream } /${ branch } ...HEAD` ;
186
- const gitCmd = verbose ? [ 'log' , '--oneline' , ref ] : [ 'rev-list' , ref ] ;
214
+ const gitCmd = verbose
215
+ ? [ 'log' , '--oneline' , '--reverse' , ref ] : [ 'rev-list' , '--reverse' , ref ] ;
187
216
const revs = runSync ( 'git' , gitCmd ) . trim ( ) ;
188
217
return revs ? revs . split ( '\n' ) : [ ] ;
189
218
}
190
219
220
+ getUpstreamHead ( verbose ) {
221
+ const { upstream, branch } = this ;
222
+ return runSync ( 'git' , [ 'rev-parse' , `${ upstream } /${ branch } ^1` ] ) . trim ( ) ;
223
+ }
224
+
191
225
async tryAbortAm ( ) {
192
226
const { cli } = this ;
193
227
if ( ! this . amInProgress ( ) ) {
0 commit comments