build: fix `validate-commit-message` on Windows (#28780)

Previously, the `validate-commit-message` gulp task was using the
`git log ... ^r1 r2` syntax to list commits between the base branch and
the current head. This didn't work as expected on Windows, because `^`
is the escape character. As a result, the command was equivalent to
`git log ... r1 r2` on Windows, which essentially logs all commits
reachable from either `r1` or `r2`.

This commit fixes it by switching to git's
[double-dot range notation][1] (`r1..r2`), which is an alias for the
`^r1 r2` syntax and works correctly on all platforms.

[1]: https://git-scm.com/docs/gitrevisions#_dotted_range_notations

Fixes #16830

PR Close #28780
This commit is contained in:
George Kalpakas 2019-02-17 11:00:50 +02:00 committed by Igor Minar
parent ababc5b4a4
commit 6788d86709
1 changed files with 3 additions and 3 deletions

View File

@ -31,7 +31,7 @@ module.exports = (gulp) => () => {
// We need to fetch origin explicitly because it might be stale.
// I couldn't find a reliable way to do this without fetch.
const result = shelljs.exec(
`git fetch origin ${baseBranch} && git log --reverse --format=%s HEAD ^origin/${baseBranch}`);
`git fetch origin ${baseBranch} && git log --reverse --format=%s origin/${baseBranch}..HEAD`);
if (result.code) {
throw new Error(`Failed to fetch commits: ${result.stderr}`);
@ -39,10 +39,10 @@ module.exports = (gulp) => () => {
const commitsByLine = result.trim().split(/\n/).filter(line => line != '');
console.log(`Examining ${commitsByLine.length} commits between HEAD and ${baseBranch}`);
console.log(`Examining ${commitsByLine.length} commit(s) between ${baseBranch} and HEAD`);
if (commitsByLine.length == 0) {
console.log(`There are zero new commits between this HEAD and ${baseBranch}`);
console.log(`There are zero new commits between ${baseBranch} and HEAD`);
}
const someCommitsInvalid = !commitsByLine.every(validateCommitMessage);