@@ -588,3 +588,115 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
588588 })
589589 }
590590}
591+
592+ func TestCommitLoader_extractCommitFromLine (t * testing.T ) {
593+ common := common .NewDummyCommon ()
594+ hashPool := & utils.StringPool {}
595+
596+ loader := & CommitLoader {
597+ Common : common ,
598+ }
599+
600+ scenarios := []struct {
601+ testName string
602+ line string
603+ showDivergence bool
604+ expectedNil bool
605+ }{
606+ {
607+ testName : "normal commit line with all fields" ,
608+ line : "0eea75e8c631fba6b58135697835d58ba4c18dbc\x00 1640826609\x00 Jesse Duffield\x00 jessedduffield@gmail.com\x00 b21997d6b4cbdf84b149\x00 >\x00 HEAD -> better-tests\x00 better typing for rebase mode" ,
609+ showDivergence : true ,
610+ expectedNil : false ,
611+ },
612+ {
613+ testName : "normal commit line with left divergence" ,
614+ line : "hash123\x00 1234567890\x00 John Doe\x00 john@example.com\x00 parent1 parent2\x00 <\x00 origin/main\x00 commit message" ,
615+ showDivergence : true ,
616+ expectedNil : false ,
617+ },
618+ {
619+ testName : "commit line with tags in extraInfo" ,
620+ line : "abc123\x00 1640000000\x00 Jane Smith\x00 jane@example.com\x00 parenthash\x00 >\x00 tag: v1.0, tag: release\x00 tagged release" ,
621+ showDivergence : true ,
622+ expectedNil : false ,
623+ },
624+ {
625+ testName : "commit line with empty extraInfo" ,
626+ line : "def456\x00 1640000000\x00 Bob Wilson\x00 bob@example.com\x00 parenthash\x00 >\x00 \x00 simple commit" ,
627+ showDivergence : true ,
628+ expectedNil : false ,
629+ },
630+ {
631+ testName : "commit line with no parents (root commit)" ,
632+ line : "root123\x00 1640000000\x00 Alice Cooper\x00 alice@example.com\x00 \x00 >\x00 \x00 initial commit" ,
633+ showDivergence : true ,
634+ expectedNil : false ,
635+ },
636+ {
637+ testName : "malformed line with only 3 fields" ,
638+ line : "hash\x00 timestamp\x00 author" ,
639+ showDivergence : false ,
640+ expectedNil : true ,
641+ },
642+ {
643+ testName : "malformed line with only 4 fields" ,
644+ line : "hash\x00 timestamp\x00 author\x00 email" ,
645+ showDivergence : false ,
646+ expectedNil : true ,
647+ },
648+ {
649+ testName : "malformed line with only 5 fields" ,
650+ line : "hash\x00 timestamp\x00 author\x00 email\x00 parents" ,
651+ showDivergence : false ,
652+ expectedNil : true ,
653+ },
654+ {
655+ testName : "malformed line with only 6 fields" ,
656+ line : "hash\x00 timestamp\x00 author\x00 email\x00 parents\x00 <" ,
657+ showDivergence : true ,
658+ expectedNil : true ,
659+ },
660+ {
661+ testName : "minimal valid line with 7 fields (no message)" ,
662+ line : "hash\x00 timestamp\x00 author\x00 email\x00 parents\x00 >\x00 extraInfo" ,
663+ showDivergence : true ,
664+ expectedNil : false ,
665+ },
666+ {
667+ testName : "minimal valid line with 7 fields (empty extraInfo)" ,
668+ line : "hash\x00 timestamp\x00 author\x00 email\x00 parents\x00 >\x00 " ,
669+ showDivergence : true ,
670+ expectedNil : false ,
671+ },
672+ {
673+ testName : "valid line with 8 fields (complete)" ,
674+ line : "hash\x00 timestamp\x00 author\x00 email\x00 parents\x00 <\x00 extraInfo\x00 message" ,
675+ showDivergence : true ,
676+ expectedNil : false ,
677+ },
678+ {
679+ testName : "empty line" ,
680+ line : "" ,
681+ showDivergence : false ,
682+ expectedNil : true ,
683+ },
684+ {
685+ testName : "line with special characters in commit message" ,
686+ line : "special123\x00 1640000000\x00 Dev User\x00 dev@example.com\x00 parenthash\x00 >\x00 \x00 fix: handle \x00 null bytes and 'quotes'" ,
687+ showDivergence : true ,
688+ expectedNil : false ,
689+ },
690+ }
691+
692+ for _ , scenario := range scenarios {
693+ t .Run (scenario .testName , func (t * testing.T ) {
694+ result := loader .extractCommitFromLine (hashPool , scenario .line , scenario .showDivergence )
695+ if scenario .expectedNil {
696+ assert .Nil (t , result )
697+ } else {
698+ assert .NotNil (t , result )
699+ }
700+ })
701+ }
702+ }
0 commit comments