@@ -138,14 +138,22 @@ class LandingSession extends Session {
138138 // TODO: do git rebase automatically?
139139 }
140140
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+
141149 async amend ( ) {
142150 const { cli } = this ;
143151 if ( ! this . readyToAmend ( ) ) {
144152 cli . warn ( 'Not yet ready to amend, run `git node land --abort`' ) ;
145153 return ;
146154 }
147155
148- const rev = runSync ( 'git' , [ 'rev-parse' , 'HEAD' ] ) ;
156+ const rev = this . getCurrentRev ( ) ;
149157 const original = runSync ( 'git' , [
150158 'show' , 'HEAD' , '-s' , '--format=%B'
151159 ] ) . trim ( ) ;
@@ -311,11 +319,60 @@ class LandingSession extends Session {
311319
312320 const branchName = `${ upstream } /${ branch } ` ;
313321 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 } ?` ) ;
315323 if ( shouldResetHead ) {
316324 await this . tryResetHead ( ) ;
317325 }
318326 }
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+ }
319376}
320377
321378module . exports = LandingSession ;
0 commit comments