-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(commits): add helpful error when lastRelease not in history
- Loading branch information
1 parent
a2d6db2
commit 5cc7da6
Showing
4 changed files
with
74 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,64 @@ | ||
const { exec } = require('child_process') | ||
|
||
module.exports = function ({lastRelease}, cb) { | ||
const log = require('npmlog') | ||
|
||
const SemanticReleaseError = require('@semantic-release/error') | ||
|
||
module.exports = function ({lastRelease, branch}, cb) { | ||
const from = lastRelease.gitHead | ||
const range = (from ? from + '..' : '') + 'HEAD' | ||
|
||
exec( | ||
`git log -E --format=%H==SPLIT==%B==END== ${range}`, | ||
(err, stdout) => { | ||
if (err) return cb(err) | ||
if (!from) return extract() | ||
|
||
cb(null, String(stdout).split('==END==\n') | ||
exec(`git branch --contains ${from}`, (err, stdout) => { | ||
if (err) return cb(err) | ||
let inHistory = false | ||
|
||
.filter((raw) => !!raw.trim()) | ||
const branches = stdout.split('\n') | ||
.map((result) => { | ||
if (branch === result.replace('*', '').trim()) { | ||
inHistory = true | ||
return null | ||
} | ||
return result.trim() | ||
}) | ||
.filter(branch => !!branch) | ||
|
||
.map((raw) => { | ||
const data = raw.split('==SPLIT==') | ||
return { | ||
hash: data[0], | ||
message: data[1] | ||
} | ||
})) | ||
if (!inHistory) { | ||
log.error('commits', | ||
`The commit the last release of this package was derived from is no longer | ||
in the direct history of the "${branch}" branch. | ||
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. | ||
You can recover from this error by publishing manually or restoring | ||
the commit "${from}".` + (branches.length ? | ||
`\nHere is a list of branches that still contain the commit in question: \n * ${branches.join('\n * ')}` : | ||
'' | ||
)) | ||
return cb(new SemanticReleaseError('Commit not in history', 'ENOTINHISTORY')) | ||
} | ||
) | ||
|
||
extract() | ||
}) | ||
|
||
function extract () { | ||
exec( | ||
`git log -E --format=%H==SPLIT==%B==END== ${range}`, | ||
(err, stdout) => { | ||
if (err) return cb(err) | ||
|
||
cb(null, String(stdout).split('==END==\n') | ||
|
||
.filter((raw) => !!raw.trim()) | ||
|
||
.map((raw) => { | ||
const data = raw.split('==SPLIT==') | ||
return { | ||
hash: data[0], | ||
message: data[1] | ||
} | ||
})) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters