ab30b2ad01
Whenever someone tries to commit (by running `git commit` directly or indirectly), a `commit-msg` git hook is run to validate the commit message. If the validation fails, an error message is printed and the commit is aborted. Occasionally, people may have written a non-trivial commit message which could turn out to be invalid (due a small typo for example). In that case, it is frustrating to "lose" the whole message and have to write it all over again (from memory). This is frustrating and has happened to me enough times to finally seek a solution. Fortunately, it turns out that git stores the last commit message in `.git/COMMIT_EDITMSG`, so it is easy to get it back (as long as you know where to look for it). This commit mentions this info in the validation error to help people that might not know about it. (This issue is probably mostly relevant for people using git from the command-line and not through a UI, but it won't hurt in either case.) PR Close #32420
35 lines
989 B
JavaScript
Executable File
35 lines
989 B
JavaScript
Executable File
#! /usr/bin/env node
|
|
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
// git commit-msg hook to check the commit message against Angular conventions
|
|
// see `/CONTRIBUTING.md` for mode details.
|
|
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const checkMsg = require('../../tools/validate-commit-message');
|
|
const msgFile = process.env['GIT_PARAMS'];
|
|
|
|
let isValid = true;
|
|
|
|
if (msgFile) {
|
|
const commitMsg = fs.readFileSync(msgFile, {encoding: 'utf-8'});
|
|
const firstLine = commitMsg.split('\n')[0];
|
|
isValid = checkMsg(firstLine);
|
|
|
|
if (!isValid) {
|
|
console.error(
|
|
'\nCheck CONTRIBUTING.md at the root of the repo for more information.' +
|
|
'\n' +
|
|
'\n(In case you need the invalid commit message, it should be stored in \'.git/COMMIT_EDITMSG\'.)');
|
|
}
|
|
}
|
|
|
|
process.exit(isValid ? 0 : 1);
|