As in many teams, me and my coworkers are putting ticket number into beginning of each commit message. If your branches are starting with ticket number it is easy to create prepare-commit-msg hook to automate this action, and since I'm a front-end deveoper, I decided to write it as a nodejs script. Look at what I came up with and tell me how to make it better if you will.
#.git/hooks/prepare-commit-msg
#!/usr/bin/env node
const fs = require('fs')
const { exec } = require('child_process')
const COMMIT_EDITMSG = process.argv[2]
exec('git symbolic-ref --short HEAD', (err, stdout) => {
if (err) throw err
fs.readFile(
COMMIT_EDITMSG,
'utf8',
(err, message) => {
if (err) throw err
fs.writeFile(
COMMIT_EDITMSG,
`${stdout.replace(/(-|_).*/, '')} ${message}`.replace(/\n/, ''),
err => {
if (err) throw err
}
)
}
)
})
return console.error(...)in all those error scenarios :) \$\endgroup\$console.error? \$\endgroup\$