Skip to content

Commit

Permalink
πŸ› fix: missing format bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Rettend committed Oct 29, 2023
1 parent e5e74d8 commit 29b7afe
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ export const main = defineCommand({
else
config = C.defaultConfig

if (!config.format.match(/{emoji}|{type}|{subject}/g))
if (!config.format)
throw new Error('Format missing in config file.')
else if (!config.format.match(/{emoji}|{type}|{subject}/g))
throw new Error('Invalid format specified in config file.')

// modify the commit message
const commitMessageFilePath = process.argv[2] ?? '.git/COMMIT_EDITMSG'
const commitMessage = fs.readFileSync(commitMessageFilePath, 'utf-8')
const firstLine = commitMessage.split('\n')[0] ?? ''

// the separator is whatever character remains after removing the format placeholders,
// if nothing remains, then the separator is a space
// the separator is whatever character remains after removing the format placeholders, or a space
const separator = config.format.replace(/{emoji}|{type}|{subject}/g, '').trim() || ' '

let [type, subject] = firstLine.split(separator)
Expand Down

0 comments on commit 29b7afe

Please sign in to comment.