mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-13 00:45:25 +02:00
parent
36a19f2569
commit
f35dcfd489
@ -6,6 +6,7 @@ package git
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
giturl "code.gitea.io/gitea/modules/git/url"
|
giturl "code.gitea.io/gitea/modules/git/url"
|
||||||
)
|
)
|
||||||
@ -13,10 +14,10 @@ import (
|
|||||||
// CommitSubmoduleFile represents a file with submodule type.
|
// CommitSubmoduleFile represents a file with submodule type.
|
||||||
type CommitSubmoduleFile struct {
|
type CommitSubmoduleFile struct {
|
||||||
refURL string
|
refURL string
|
||||||
parsedURL *giturl.RepositoryURL
|
|
||||||
parsed bool
|
|
||||||
refID string
|
refID string
|
||||||
repoLink string
|
|
||||||
|
parsed bool
|
||||||
|
targetRepoLink string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommitSubmoduleFile create a new submodule file
|
// NewCommitSubmoduleFile create a new submodule file
|
||||||
@ -35,20 +36,27 @@ func (sf *CommitSubmoduleFile) SubmoduleWebLink(ctx context.Context, optCommitID
|
|||||||
}
|
}
|
||||||
if !sf.parsed {
|
if !sf.parsed {
|
||||||
sf.parsed = true
|
sf.parsed = true
|
||||||
|
if strings.HasPrefix(sf.refURL, "../") {
|
||||||
|
// FIXME: when handling relative path, this logic is not right. It needs to:
|
||||||
|
// 1. Remember the submodule's full path and its commit's repo home link
|
||||||
|
// 2. Resolve the relative path: targetRepoLink = path.Join(repoHomeLink, path.Dir(submoduleFullPath), refURL)
|
||||||
|
// Not an easy task and need to refactor related code a lot.
|
||||||
|
sf.targetRepoLink = sf.refURL
|
||||||
|
} else {
|
||||||
parsedURL, err := giturl.ParseRepositoryURL(ctx, sf.refURL)
|
parsedURL, err := giturl.ParseRepositoryURL(ctx, sf.refURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
sf.parsedURL = parsedURL
|
sf.targetRepoLink = giturl.MakeRepositoryWebLink(parsedURL)
|
||||||
sf.repoLink = giturl.MakeRepositoryWebLink(sf.parsedURL)
|
}
|
||||||
}
|
}
|
||||||
var commitLink string
|
var commitLink string
|
||||||
if len(optCommitID) == 2 {
|
if len(optCommitID) == 2 {
|
||||||
commitLink = sf.repoLink + "/compare/" + optCommitID[0] + "..." + optCommitID[1]
|
commitLink = sf.targetRepoLink + "/compare/" + optCommitID[0] + "..." + optCommitID[1]
|
||||||
} else if len(optCommitID) == 1 {
|
} else if len(optCommitID) == 1 {
|
||||||
commitLink = sf.repoLink + "/tree/" + optCommitID[0]
|
commitLink = sf.targetRepoLink + "/tree/" + optCommitID[0]
|
||||||
} else {
|
} else {
|
||||||
commitLink = sf.repoLink + "/tree/" + sf.refID
|
commitLink = sf.targetRepoLink + "/tree/" + sf.refID
|
||||||
}
|
}
|
||||||
return &SubmoduleWebLink{RepoWebLink: sf.repoLink, CommitWebLink: commitLink}
|
return &SubmoduleWebLink{RepoWebLink: sf.targetRepoLink, CommitWebLink: commitLink}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCommitSubmoduleLink(t *testing.T) {
|
func TestCommitSubmoduleLink(t *testing.T) {
|
||||||
|
wl := (*CommitSubmoduleFile)(nil).SubmoduleWebLink(t.Context())
|
||||||
|
assert.Nil(t, wl)
|
||||||
|
|
||||||
|
t.Run("GitHubRepo", func(t *testing.T) {
|
||||||
sf := NewCommitSubmoduleFile("git@github.com:user/repo.git", "aaaa")
|
sf := NewCommitSubmoduleFile("git@github.com:user/repo.git", "aaaa")
|
||||||
|
|
||||||
wl := sf.SubmoduleWebLink(t.Context())
|
wl := sf.SubmoduleWebLink(t.Context())
|
||||||
@ -23,7 +27,12 @@ func TestCommitSubmoduleLink(t *testing.T) {
|
|||||||
wl = sf.SubmoduleWebLink(t.Context(), "1111", "2222")
|
wl = sf.SubmoduleWebLink(t.Context(), "1111", "2222")
|
||||||
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
||||||
assert.Equal(t, "https://github.com/user/repo/compare/1111...2222", wl.CommitWebLink)
|
assert.Equal(t, "https://github.com/user/repo/compare/1111...2222", wl.CommitWebLink)
|
||||||
|
})
|
||||||
|
|
||||||
wl = (*CommitSubmoduleFile)(nil).SubmoduleWebLink(t.Context())
|
t.Run("RelativePath", func(t *testing.T) {
|
||||||
assert.Nil(t, wl)
|
sf := NewCommitSubmoduleFile("../../user/repo", "aaaa")
|
||||||
|
wl := sf.SubmoduleWebLink(t.Context())
|
||||||
|
assert.Equal(t, "../../user/repo", wl.RepoWebLink)
|
||||||
|
assert.Equal(t, "../../user/repo/tree/aaaa", wl.CommitWebLink)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
#repo-files-table .repo-file-cell.name .entry-name {
|
#repo-files-table .repo-file-cell.name .entry-name {
|
||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
min-width: 3em;
|
min-width: 1ch; /* leave about one letter space when shrinking, need to fine tune the "shrinks" in this grid in the future */
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 767.98px) {
|
@media (max-width: 767.98px) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user