@@ -568,34 +568,93 @@ describe('parsePackFile', () => {
568
568
} ) ;
569
569
570
570
it ( 'should handle commit messages with multiple lines' , ( ) => {
571
- const commitContent = `tree 123\nparent 456\nauthor A <[email protected] > 111 +0000 1 \ncommitter C <[email protected] > 2 \n\nLine one\nLine two\n\nLine four` ;
571
+ const commitContent = `tree 123\nparent 456\nauthor A <[email protected] > 111 +0000\ncommitter C <[email protected] > 222 +0100 \n\nLine one\nLine two\n\nLine four` ;
572
572
const contents = [ { type : 1 , content : commitContent } ] ;
573
573
const result = getCommitData ( contents ) ;
574
574
expect ( result [ 0 ] . message ) . to . equal ( 'Line one\nLine two\n\nLine four' ) ;
575
575
} ) ;
576
576
577
+ it ( 'should handle commits without a message body' , ( ) => {
578
+ const commitContent = `tree 123\nparent 456\nauthor A <[email protected] > 111 +0000\ncommitter C <[email protected] > 222 +0100\n` ;
579
+ const contents = [ { type : 1 , content : commitContent } ] ;
580
+ const result = getCommitData ( contents ) ;
581
+ expect ( result [ 0 ] . message ) . to . equal ( '' ) ;
582
+ } ) ;
583
+
577
584
it ( 'should throw error for invalid commit data (missing tree)' , ( ) => {
578
- const commitContent = `parent 456\nauthor A <[email protected] > 1 \ncommitter C <[email protected] > 2 \n\nMsg` ;
585
+ const commitContent = `parent 456\nauthor A <[email protected] > 1234567890 +0000 \ncommitter C <[email protected] > 1234567890 +0000 \n\nMsg` ;
579
586
const contents = [ { type : 1 , content : commitContent } ] ;
580
- expect ( ( ) => getCommitData ( contents ) ) . to . throw ( 'Invalid commit data' ) ;
587
+ expect ( ( ) => getCommitData ( contents ) ) . to . throw ( 'Invalid commit data: Missing tree ' ) ;
581
588
} ) ;
582
589
583
590
it ( 'should throw error for invalid commit data (missing author)' , ( ) => {
584
- const commitContent = `tree 123\nparent 456\ncommitter C <[email protected] > 2 \n\nMsg` ;
591
+ const commitContent = `tree 123\nparent 456\ncommitter C <[email protected] > 1234567890 +0000 \n\nMsg` ;
585
592
const contents = [ { type : 1 , content : commitContent } ] ;
586
- expect ( ( ) => getCommitData ( contents ) ) . to . throw ( 'Invalid commit data' ) ;
593
+ expect ( ( ) => getCommitData ( contents ) ) . to . throw ( 'Invalid commit data: Missing author ' ) ;
587
594
} ) ;
588
595
589
596
it ( 'should throw error for invalid commit data (missing committer)' , ( ) => {
590
- const commitContent = `tree 123\nparent 456\nauthor A <[email protected] > 1 \n\nMsg` ;
597
+ const commitContent = `tree 123\nparent 456\nauthor A <[email protected] > 1234567890 +0000 \n\nMsg` ;
591
598
const contents = [ { type : 1 , content : commitContent } ] ;
592
- expect ( ( ) => getCommitData ( contents ) ) . to . throw ( 'Invalid commit data' ) ;
599
+ expect ( ( ) => getCommitData ( contents ) ) . to . throw ( 'Invalid commit data: Missing committer ' ) ;
593
600
} ) ;
594
601
595
- it ( 'should throw error for invalid commit data (missing message separator )' , ( ) => {
596
- const commitContent = `tree 123\nparent 456\nauthor A <[email protected] > 1 \ncommitter C <[email protected] > 2` ; // No empty line
602
+ it ( 'should throw error for invalid author line (missing timezone offset )' , ( ) => {
603
+ const commitContent = `tree 123\nparent 456\nauthor A <[email protected] > 1234567890 \ncommitter C <[email protected] > 1234567890 +0000\n\nMsg` ;
597
604
const contents = [ { type : 1 , content : commitContent } ] ;
598
- expect ( ( ) => getCommitData ( contents ) ) . to . throw ( 'Invalid commit data' ) ;
605
+ expect ( ( ) => getCommitData ( contents ) ) . to . throw ( 'Failed to parse person line' ) ;
606
+ } ) ;
607
+
608
+ it ( 'should correctly parse a commit with a GPG signature header' , ( ) => {
609
+ const gpgSignedCommit = "tree b4d3c0ffee1234567890abcdef1234567890aabbcc\n" +
610
+ "parent 01dbeef9876543210fedcba9876543210fedcba\n" +
611
+ "author Test Author <[email protected] > 1744814600 +0100\n" +
612
+ "committer Test Committer <[email protected] > 1744814610 +0200\n" +
613
+ "gpgsig -----BEGIN PGP SIGNATURE-----\n\n" +
614
+ " wsFcBAABCAAQBQJn/8ISCRC1aQ7uu5UhlAAAntAQACeyQd6IykNXiN6m9DfVp8DJ\n" +
615
+ " UsY64ws+Td0inrEee+cHXVI9uJn15RJYQkICwlM4TZsVGav7nYaVqO+gfAg2ORAH\n" +
616
+ " ghUnwSFFs7ucN/p0a47ItkJmt04+jQIFlZIC+wy1u2H3aKJwqaF+kGP5SA33ahgV\n" +
617
+ " ZWviKodXFki8/G+sKB63q1qrDw6aELtftEgeAPQUcuLzj+vu/m3dWrDbatfUXMkC\n" +
618
+ " JC6PbFajqrJ5pEtFwBqqRE+oIsOM9gkNAti1yDD5eoS+bNXACe0hT0+UoIzn5a34\n" +
619
+ " xcElXTSdAK/MRjGiLN91G2nWvlbpM5wAEqr5Bl5ealCc6BbWfPxbP46slaE5DfkD\n" +
620
+ " u0+RkVX06MSSPqzOmEV14ZWKap5C19FpF9o/rY8vtLlCxjWMhtUvvdR4OQfQpEDY\n" +
621
+ " eTqzCHRnM3+7r3ABAWt9v7cG99bIMEs3sGcMy11HMeaoBpye6vCIP4ghNnoB1hUJ\n" +
622
+ " D7MD77jzk4Kbf4IzS5omExyMu3AiNZecZX4+1w/527yPhv3s/HB1Gfz0oCUned+6\n" +
623
+ " b9Kkle+krsQ/EK/4gPcb/Kb1cTcm3HhjaOSYwA+JpApJQ0mrduH34AT5MZJuIPFe\n" +
624
+ " QheLzQI1d2jmFs11GRC5hc0HBk1WmGm6U8+FBuxCX0ECZPdYeQJjUeWjnNeUoE6a\n" +
625
+ " 5lytZU4Onk57nUhIMSrx\n" +
626
+ " =IxZr\n" +
627
+ " -----END PGP SIGNATURE-----\n\n" +
628
+ "This is the commit message.\n" +
629
+ "It can span multiple lines.\n\n" +
630
+ "And include blank lines internally." ;
631
+
632
+ const contents = [
633
+ { type : 1 , content : gpgSignedCommit } ,
634
+ { type :
1 , content :
`tree 111\nparent 000\nauthor A1 <[email protected] > 1744814600 +0200\ncommitter C1 <[email protected] > 1744814610 +0200\n\nMsg1` }
635
+ ] ;
636
+
637
+ const result = getCommitData ( contents ) ;
638
+ expect ( result ) . to . be . an ( 'array' ) . with . lengthOf ( 2 ) ;
639
+
640
+ // Check the GPG signed commit data
641
+ const gpgResult = result [ 0 ] ;
642
+ expect ( gpgResult . tree ) . to . equal ( 'b4d3c0ffee1234567890abcdef1234567890aabbcc' ) ;
643
+ expect ( gpgResult . parent ) . to . equal ( '01dbeef9876543210fedcba9876543210fedcba' ) ;
644
+ expect ( gpgResult . author ) . to . equal ( 'Test Author' ) ;
645
+ expect ( gpgResult . committer ) . to . equal ( 'Test Committer' ) ;
646
+ expect ( gpgResult . authorEmail ) . to . equal ( '[email protected] ' ) ;
647
+ expect ( gpgResult . commitTimestamp ) . to . equal ( '1744814610' ) ;
648
+ expect ( gpgResult . message ) . to . equal ( `This is the commit message.\nIt can span multiple lines.\n\nAnd include blank lines internally.` ) ;
649
+
650
+ // Sanity check: the second commit should be the simple commit
651
+ const simpleResult = result [ 1 ] ;
652
+ expect ( simpleResult . message ) . to . equal ( 'Msg1' ) ;
653
+ expect ( simpleResult . parent ) . to . equal ( '000' ) ;
654
+ expect ( simpleResult . author ) . to . equal ( 'A1' ) ;
655
+ expect ( simpleResult . committer ) . to . equal ( 'C1' ) ;
656
+ expect ( simpleResult . authorEmail ) . to . equal ( '[email protected] ' ) ;
657
+ expect ( simpleResult . commitTimestamp ) . to . equal ( '1744814610' ) ;
599
658
} ) ;
600
659
} ) ;
601
660
0 commit comments