11import { execa } from 'execa'
2+ import type { GitPluginOptions } from '../options.js'
23import type { GitContributor , MergedRawCommit , RawCommit } from '../typings.js'
34
4- const FORMAT = '%H|%an|%ae|%ad|%s|%d|%b'
55const SPLIT_CHAR = '[GIT_LOG_COMMIT_END]'
66const RE_SPLIT = / \[ G I T _ L O G _ C O M M I T _ E N D \] $ /
77
@@ -20,6 +20,15 @@ const getCoAuthors = (
2020 . filter ( Boolean )
2121}
2222
23+ const getFormat = ( { contributors, changelog } : GitPluginOptions ) : string => {
24+ // hash | _ | _ | author_date | _ | _ | _
25+ if ( ! contributors && ! changelog ) return '%H|||%ad|||'
26+ // hash | author_name | author_email | author_date | _ | _ | body
27+ if ( contributors && ! changelog ) return '%H|%an|%ae|%ad|||%b'
28+ // hash | author_name | author_email | author_date | subject | ref | body
29+ return '%H|%an|%ae|%ad|%s|%d|%b'
30+ }
31+
2332/**
2433 * Get raw commits
2534 *
@@ -30,14 +39,16 @@ const getCoAuthors = (
3039export const getRawCommits = async (
3140 filepath : string ,
3241 cwd : string ,
42+ options : GitPluginOptions ,
3343) : Promise < RawCommit [ ] > => {
44+ const format = getFormat ( options )
3445 try {
3546 const { stdout } = await execa (
3647 'git' ,
3748 [
3849 'log' ,
3950 '--max-count=-1' ,
40- `--format=${ FORMAT } ${ SPLIT_CHAR } ` ,
51+ `--format=${ format } ${ SPLIT_CHAR } ` ,
4152 '--date=unix' ,
4253 '--follow' ,
4354 '--' ,
@@ -87,9 +98,10 @@ export const mergeRawCommits = (commits: RawCommit[]): MergedRawCommit[] => {
8798export const getCommits = async (
8899 filepaths : string [ ] ,
89100 cwd : string ,
101+ options : GitPluginOptions ,
90102) : Promise < MergedRawCommit [ ] > => {
91103 const rawCommits = await Promise . all (
92- filepaths . map ( ( filepath ) => getRawCommits ( filepath , cwd ) ) ,
104+ filepaths . map ( ( filepath ) => getRawCommits ( filepath , cwd , options ) ) ,
93105 )
94106
95107 return mergeRawCommits ( rawCommits . flat ( ) ) . sort ( ( a , b ) =>
0 commit comments