@@ -13,10 +13,11 @@ import (
1313
1414// CommitSubmoduleFile represents a file with submodule type.
1515type CommitSubmoduleFile struct {
16- refURL string
17- parsed bool
18- refID string
19- repoLink string
16+ refURL string
17+ refID string
18+
19+ parsed bool
20+ targetRepoLink string
2021}
2122
2223// NewCommitSubmoduleFile create a new submodule file
@@ -37,26 +38,25 @@ func (sf *CommitSubmoduleFile) SubmoduleWebLink(ctx context.Context, optCommitID
3738 sf .parsed = true
3839 if strings .HasPrefix (sf .refURL , "../" ) {
3940 // FIXME: when handling relative path, this logic is not right. It needs to:
40- // 1. Remember the submodule's full path
41- // 2. Resolve the relative path based on submodule's full path, and still keep the unresolved relative path
42- // 3. Resolve the unresolved relative path based on the current repository's URL
41+ // 1. Remember the submodule's full path and its commit's repo home link
42+ // 2. Resolve the relative path: targetRepoLink = path.Join(repoHomeLink, path.Dir(submoduleFullPath), refURL)
4343 // Not an easy task and need to refactor related code a lot.
44- sf .repoLink = sf .refURL
44+ sf .targetRepoLink = sf .refURL
4545 } else {
4646 parsedURL , err := giturl .ParseRepositoryURL (ctx , sf .refURL )
4747 if err != nil {
4848 return nil
4949 }
50- sf .repoLink = giturl .MakeRepositoryWebLink (parsedURL )
50+ sf .targetRepoLink = giturl .MakeRepositoryWebLink (parsedURL )
5151 }
5252 }
5353 var commitLink string
5454 if len (optCommitID ) == 2 {
55- commitLink = sf .repoLink + "/compare/" + optCommitID [0 ] + "..." + optCommitID [1 ]
55+ commitLink = sf .targetRepoLink + "/compare/" + optCommitID [0 ] + "..." + optCommitID [1 ]
5656 } else if len (optCommitID ) == 1 {
57- commitLink = sf .repoLink + "/tree/" + optCommitID [0 ]
57+ commitLink = sf .targetRepoLink + "/tree/" + optCommitID [0 ]
5858 } else {
59- commitLink = sf .repoLink + "/tree/" + sf .refID
59+ commitLink = sf .targetRepoLink + "/tree/" + sf .refID
6060 }
61- return & SubmoduleWebLink {RepoWebLink : sf .repoLink , CommitWebLink : commitLink }
61+ return & SubmoduleWebLink {RepoWebLink : sf .targetRepoLink , CommitWebLink : commitLink }
6262}
0 commit comments