@@ -29,12 +29,16 @@ func NewCommitSubmoduleFile(repoLink, fullPath, refURL, refID string) *CommitSub
2929 return & CommitSubmoduleFile {repoLink : repoLink , fullPath : fullPath , refURL : refURL , refID : refID }
3030}
3131
32+ // RefID returns the commit ID of the submodule, it returns empty string for nil receiver
3233func (sf * CommitSubmoduleFile ) RefID () string {
34+ if sf == nil {
35+ return ""
36+ }
3337 return sf .refID
3438}
3539
3640func (sf * CommitSubmoduleFile ) getWebLinkInTargetRepo (ctx context.Context , moreLinkPath string ) * SubmoduleWebLink {
37- if sf == nil {
41+ if sf == nil || sf . refURL == "" {
3842 return nil
3943 }
4044 if strings .HasPrefix (sf .refURL , "../" ) {
@@ -53,14 +57,13 @@ func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreL
5357}
5458
5559// SubmoduleWebLinkTree tries to make the submodule's tree link in its own repo, it also works on "nil" receiver
60+ // It returns nil if the submodule does not have a valid URL or is nil
5661func (sf * CommitSubmoduleFile ) SubmoduleWebLinkTree (ctx context.Context , optCommitID ... string ) * SubmoduleWebLink {
57- if sf == nil {
58- return nil
59- }
60- return sf .getWebLinkInTargetRepo (ctx , "/tree/" + util .OptionalArg (optCommitID , sf .refID ))
62+ return sf .getWebLinkInTargetRepo (ctx , "/tree/" + util .OptionalArg (optCommitID , sf .RefID ()))
6163}
6264
6365// SubmoduleWebLinkCompare tries to make the submodule's compare link in its own repo, it also works on "nil" receiver
66+ // It returns nil if the submodule does not have a valid URL or is nil
6467func (sf * CommitSubmoduleFile ) SubmoduleWebLinkCompare (ctx context.Context , commitID1 , commitID2 string ) * SubmoduleWebLink {
6568 return sf .getWebLinkInTargetRepo (ctx , "/compare/" + commitID1 + "..." + commitID2 )
6669}
0 commit comments