@@ -360,7 +360,6 @@ type DiffFile struct {
360360 IsLFSFile bool
361361 IsRenamed bool
362362 IsAmbiguous bool
363- IsSubmodule bool
364363 Sections []* DiffSection
365364 IsIncomplete bool
366365 IsIncompleteLineTooLong bool
@@ -372,7 +371,9 @@ type DiffFile struct {
372371 Language string
373372 Mode string
374373 OldMode string
375- SubmoduleInfo * SubmoduleInfo
374+
375+ IsSubmodule bool // if IsSubmodule==true, then there must be a SubmoduleInfo
376+ SubmoduleInfo * SubmoduleInfo
376377}
377378
378379// GetType returns type of diff file.
@@ -610,9 +611,8 @@ parsingLoop:
610611 if strings .HasPrefix (line , "new mode " ) {
611612 curFile .Mode = prepareValue (line , "new mode " )
612613 }
613-
614614 if strings .HasSuffix (line , " 160000\n " ) {
615- curFile .IsSubmodule = true
615+ curFile .IsSubmodule , curFile . SubmoduleInfo = true , & SubmoduleInfo {}
616616 }
617617 case strings .HasPrefix (line , "rename from " ):
618618 curFile .IsRenamed = true
@@ -647,17 +647,17 @@ parsingLoop:
647647 curFile .Mode = prepareValue (line , "new file mode " )
648648 }
649649 if strings .HasSuffix (line , " 160000\n " ) {
650- curFile .IsSubmodule = true
650+ curFile .IsSubmodule , curFile . SubmoduleInfo = true , & SubmoduleInfo {}
651651 }
652652 case strings .HasPrefix (line , "deleted" ):
653653 curFile .Type = DiffFileDel
654654 curFile .IsDeleted = true
655655 if strings .HasSuffix (line , " 160000\n " ) {
656- curFile .IsSubmodule = true
656+ curFile .IsSubmodule , curFile . SubmoduleInfo = true , & SubmoduleInfo {}
657657 }
658658 case strings .HasPrefix (line , "index" ):
659659 if strings .HasSuffix (line , " 160000\n " ) {
660- curFile .IsSubmodule = true
660+ curFile .IsSubmodule , curFile . SubmoduleInfo = true , & SubmoduleInfo {}
661661 }
662662 case strings .HasPrefix (line , "similarity index 100%" ):
663663 curFile .Type = DiffFileRename
@@ -918,11 +918,7 @@ func parseHunks(ctx context.Context, curFile *DiffFile, maxLines, maxLineCharact
918918 curSection .Lines = append (curSection .Lines , diffLine )
919919
920920 // Parse submodule additions
921- if curFile .IsSubmodule {
922- if curFile .SubmoduleInfo == nil {
923- curFile .SubmoduleInfo = & SubmoduleInfo {}
924- }
925-
921+ if curFile .SubmoduleInfo != nil {
926922 if ref , found := bytes .CutPrefix (lineBytes , []byte ("+Subproject commit " )); found {
927923 curFile .SubmoduleInfo .NewRefID = string (bytes .TrimSpace (ref ))
928924 }
@@ -950,11 +946,7 @@ func parseHunks(ctx context.Context, curFile *DiffFile, maxLines, maxLineCharact
950946 curSection .Lines = append (curSection .Lines , diffLine )
951947
952948 // Parse submodule deletion
953- if curFile .IsSubmodule {
954- if curFile .SubmoduleInfo == nil {
955- curFile .SubmoduleInfo = & SubmoduleInfo {}
956- }
957-
949+ if curFile .SubmoduleInfo != nil {
958950 if ref , found := bytes .CutPrefix (lineBytes , []byte ("-Subproject commit " )); found {
959951 curFile .SubmoduleInfo .PreviousRefID = string (bytes .TrimSpace (ref ))
960952 }
@@ -1219,7 +1211,7 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi
12191211 }
12201212
12211213 // Populate Submodule URLs
1222- if diffFile .IsSubmodule && diffFile . SubmoduleInfo != nil {
1214+ if diffFile .SubmoduleInfo != nil {
12231215 err := diffFile .SubmoduleInfo .PopulateURL (diffFile , beforeCommit , commit )
12241216 if err != nil {
12251217 return nil , err
0 commit comments