fix(commits): handle failing git command correctly and show meaningful error
Closes #83
This commit is contained in:
		
							parent
							
								
									a3f561d1d1
								
							
						
					
					
						commit
						cb3992595e
					
				| @ -12,27 +12,27 @@ module.exports = function ({lastRelease, options}, cb) { | |||||||
|   if (!from) return extract() |   if (!from) return extract() | ||||||
| 
 | 
 | ||||||
|   exec(`git branch --contains ${from}`, (err, stdout) => { |   exec(`git branch --contains ${from}`, (err, stdout) => { | ||||||
|     if (err) return cb(err) |  | ||||||
|     let inHistory = false |     let inHistory = false | ||||||
|  |     let branches | ||||||
| 
 | 
 | ||||||
|     const branches = stdout.split('\n') |     if (!err && stdout) { | ||||||
|     .map((result) => { |       branches = stdout.split('\n') | ||||||
|       if (branch === result.replace('*', '').trim()) { |       .map((result) => { | ||||||
|         inHistory = true |         if (branch === result.replace('*', '').trim()) { | ||||||
|         return null |           inHistory = true | ||||||
|       } |           return null | ||||||
|       return result.trim() |         } | ||||||
|     }) |         return result.trim() | ||||||
|     .filter(branch => !!branch) |       }) | ||||||
|  |       .filter(branch => !!branch) | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     if (!inHistory) { |     if (!inHistory) { | ||||||
|       log.error('commits', |       log.error('commits', | ||||||
| `The commit the last release of this package was derived from is no longer
 | `The commit the last release of this package was derived from is not in the direct history of the "${branch}" branch.
 | ||||||
| in the direct history of the "${branch}" branch. |  | ||||||
| This means semantic-release can not extract the commits between now and then. | This means semantic-release can not extract the commits between now and then. | ||||||
| This is usually caused by force pushing or releasing from an unrelated branch. | This is usually caused by force pushing, releasing from an unrelated branch, or using an already existing package name. | ||||||
| You can recover from this error by publishing manually or restoring | You can recover from this error by publishing manually or restoring the commit "${from}".` + (branches && branches.length ?
 | ||||||
| the commit "${from}".` + (branches.length ?
 |  | ||||||
|         `\nHere is a list of branches that still contain the commit in question: \n * ${branches.join('\n * ')}` : |         `\nHere is a list of branches that still contain the commit in question: \n * ${branches.join('\n * ')}` : | ||||||
|         '' |         '' | ||||||
|       )) |       )) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user