diff --git a/hellotech/.config/git/template/hooks/prepare-commit-msg b/hellotech/.config/git/template/hooks/prepare-commit-msg index 6827ed3..d40daea 100755 --- a/hellotech/.config/git/template/hooks/prepare-commit-msg +++ b/hellotech/.config/git/template/hooks/prepare-commit-msg @@ -8,11 +8,20 @@ const exec = promisify(childProcess.exec); const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); -const [, , commitMsg, comitSrc, sha1] = process.argv; +const [, , message, mode] = process.argv; async function main() { - const file = await readFile(commitMsg, { encoding: "utf8" }); - const result = await exec("git symbolic-ref --short HEAD"); + const file = await readFile(message, { encoding: "utf8" }); + let result; + try { + result = await exec("git rev-parse --abbrev-ref HEAD"); + } catch (err) { + return + } + + if (message.match(/^#/)) { + return + } const tags = result.stdout .split("\n") @@ -27,8 +36,12 @@ async function main() { if (tags.find(tag => file.includes(tag))) { return; } - const newFile = "\n\n# " + tags.join(" ") + "\n" + file; - await writeFile(commitMsg, newFile); + + const newFile = mode === 'message' + ? file + '\n\n' + tags.join(" ") + : `\n\n# ` + tags.join(" ") + "\n" + file; + + await writeFile(message, newFile); } main().catch(err => {