@@ -138,14 +138,22 @@ class LandingSession extends Session {
138
138
// TODO: do git rebase automatically?
139
139
}
140
140
141
+ getCurrentRev ( ) {
142
+ return runSync ( 'git' , [ 'rev-parse' , 'HEAD' ] ) . trim ( ) ;
143
+ }
144
+
145
+ getCurrentBranch ( ) {
146
+ return runSync ( 'git' , [ 'rev-parse' , '--abbrev-ref' , 'HEAD' ] ) . trim ( ) ;
147
+ }
148
+
141
149
async amend ( ) {
142
150
const { cli } = this ;
143
151
if ( ! this . readyToAmend ( ) ) {
144
152
cli . warn ( 'Not yet ready to amend, run `git node land --abort`' ) ;
145
153
return ;
146
154
}
147
155
148
- const rev = runSync ( 'git' , [ 'rev-parse' , 'HEAD' ] ) ;
156
+ const rev = this . getCurrentRev ( ) ;
149
157
const original = runSync ( 'git' , [
150
158
'show' , 'HEAD' , '-s' , '--format=%B'
151
159
] ) . trim ( ) ;
@@ -311,11 +319,60 @@ class LandingSession extends Session {
311
319
312
320
const branchName = `${ upstream } /${ branch } ` ;
313
321
const shouldResetHead = await cli . prompt (
314
- `Do you want to try reset the branch to ${ branchName } ?` ) ;
322
+ `Do you want to try reset the local ${ branch } branch to ${ branchName } ?` ) ;
315
323
if ( shouldResetHead ) {
316
324
await this . tryResetHead ( ) ;
317
325
}
318
326
}
327
+
328
+ warnForMissing ( ) {
329
+ const { upstream, branch, cli } = this ;
330
+ const missing = ! upstream || ! branch ;
331
+ if ( ! branch ) {
332
+ cli . warn ( 'You have not told git-node what branch you are trying' +
333
+ ' to land commits on.' ) ;
334
+ cli . separator ( ) ;
335
+ cli . info (
336
+ 'For example, if your want to land commits on the ' +
337
+ '`master` branch, you can run:\n\n' +
338
+ ' $ ncu-config set branch master' ) ;
339
+ cli . separator ( ) ;
340
+ }
341
+ if ( ! upstream ) {
342
+ cli . warn ( 'You have not told git-node the remote you want to sync with.' ) ;
343
+ cli . separator ( ) ;
344
+ cli . info (
345
+ 'For example, if your remote pointing to nodejs/node is' +
346
+ ' `remote-upstream`, you can run:\n\n' +
347
+ ' $ ncu-config set upstream remote-upstream' ) ;
348
+ cli . separator ( ) ;
349
+ }
350
+ return missing ;
351
+ }
352
+
353
+ warnForWrongBranch ( ) {
354
+ const { branch, cli } = this ;
355
+ let rev = this . getCurrentBranch ( ) ;
356
+ if ( rev === 'HEAD' ) {
357
+ cli . warn (
358
+ 'You are in detached HEAD state. Please run git-node on a valid ' +
359
+ 'branch' ) ;
360
+ return true ;
361
+ }
362
+ if ( rev === branch ) {
363
+ return false ;
364
+ }
365
+ cli . warn (
366
+ `You are running git-node-land on \`${ rev } \`,\n but you have` +
367
+ ` configured \`${ branch } \` to be the branch to land commits.` ) ;
368
+ cli . separator ( ) ;
369
+ cli . info (
370
+ `You can switch to \`${ branch } \` with \`git checkout ${ branch } \`, or\n` +
371
+ ` reconfigure the target branch with:\n\n` +
372
+ ` $ ncu-config set branch ${ rev } ` ) ;
373
+ cli . separator ( ) ;
374
+ return true ;
375
+ }
319
376
}
320
377
321
378
module . exports = LandingSession ;
0 commit comments