@@ -247,3 +247,57 @@ test('line before first commit header emits error on write', async () => {
247247 const [ err ] = await error
248248 assert . strictEqual ( err . message , 'Unexpected line before first "commit" header: garbage' )
249249} )
250+
251+ for ( const decoration of [ '(HEAD -> main)' , '(tag: v1.0.0, origin/main)' , '(from 1111111111111111111111111111111111111111)' ] ) {
252+ test ( `decorated commit header ${ decoration } ` , async ( ) => {
253+ // first header plain, second decorated: exercises the "merged into previous commit" path
254+ const log = ( sha , name , summary , header = `commit ${ sha } ${ decoration } ` ) => [
255+ header ,
256+ `Author: ${ name } <${ name } @example.com>` ,
257+ 'Date: Fri Nov 22 00:19:29 2024 -0300' ,
258+ '' ,
259+ ` ${ summary } ` ,
260+ ''
261+ ]
262+ const commits = await toCommits ( [
263+ ...log ( '2222222222222222222222222222222222222222' , 'first' , 'first summary' , 'commit 2222222222222222222222222222222222222222' ) ,
264+ ...log ( '3333333333333333333333333333333333333333' , 'second' , 'second summary' )
265+ ] )
266+ assert . deepStrictEqual ( commits , [
267+ {
268+ sha : '2222222222222222222222222222222222222222' ,
269+ author : { name : 'first' , email : 'first@example.com' } ,
270+ authors : [ { name : 'first' , email : 'first@example.com' } ] ,
271+ authorDate : 'Fri Nov 22 00:19:29 2024 -0300' ,
272+ summary : 'first summary'
273+ } ,
274+ {
275+ sha : '3333333333333333333333333333333333333333' ,
276+ author : { name : 'second' , email : 'second@example.com' } ,
277+ authors : [ { name : 'second' , email : 'second@example.com' } ] ,
278+ authorDate : 'Fri Nov 22 00:19:29 2024 -0300' ,
279+ summary : 'second summary'
280+ }
281+ ] )
282+ } )
283+ }
284+
285+ for ( const args of [ [ '--decorate=short' ] , [ '--decorate=short' , '--color=always' ] , [ '-c' , 'log.decorate=short' ] ] ) {
286+ test ( `git log ${ args . join ( ' ' ) } matches undecorated log` , async ( ) => {
287+ const gitArgs = args [ 0 ] === '-c' ? [ ...args , 'log' ] : [ 'log' , ...args ]
288+ assert . deepStrictEqual ( await gitToList ( gitArgs ) , await gitToList ( [ 'log' , '--no-decorate' ] ) )
289+ } )
290+ }
291+
292+ test ( 'git log -m parses "(from <sha>)" merge headers' , async ( ) => {
293+ const list = await gitToList ( [ 'log' , '-m' , '--stat' , '--no-decorate' , '8d59e56..1a19a1d' ] )
294+ assert . deepStrictEqual (
295+ list . map ( ( c ) => [ c . sha , c . authors ?. length , c . summary ] ) ,
296+ [
297+ [ '1a19a1da92a1657592b52d94d24678c5c5659883' , 1 , 'Merge pull request #19 from nodejs/add-write-permission' ] ,
298+ [ '776bc302aebaef471870b56586572225325af238' , 1 , 'fix: add permissions: write to create release action' ] ,
299+ [ '6d8cfef1f2f8618bc363ac73dae3e4075127ab4d' , 1 , 'Merge pull request #18 from nodejs/change-repository-to-nodejs' ] ,
300+ [ '1c30cfb55cc0d280c71eec1c1462e067b3214113' , 1 , 'meta: change repository to nodejs' ]
301+ ]
302+ )
303+ } )
0 commit comments