From 134cd0e3e392797f24fbac7fabd4f70f71f7509b Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Mon, 26 Jul 2021 19:14:47 -0700 Subject: [PATCH] Fix issue with rebase format and message type --- .../git/template/hooks/prepare-commit-msg | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 => {