From ff266a7e5befbd3f9b2b569cc60d91e9098c48f1 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 10 Jul 2025 21:17:33 +0800 Subject: [PATCH 1/4] fix --- modules/git/commit_submodule_file.go | 23 +++++++++------- modules/git/commit_submodule_file_test.go | 33 ++++++++++++++--------- web_src/css/repo/home-file-list.css | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/modules/git/commit_submodule_file.go b/modules/git/commit_submodule_file.go index 729401f752112..08a8c3ff4d0e3 100644 --- a/modules/git/commit_submodule_file.go +++ b/modules/git/commit_submodule_file.go @@ -6,17 +6,17 @@ package git import ( "context" + "strings" giturl "code.gitea.io/gitea/modules/git/url" ) // CommitSubmoduleFile represents a file with submodule type. type CommitSubmoduleFile struct { - refURL string - parsedURL *giturl.RepositoryURL - parsed bool - refID string - repoLink string + refURL string + parsed bool + refID string + repoLink string } // NewCommitSubmoduleFile create a new submodule file @@ -35,12 +35,15 @@ func (sf *CommitSubmoduleFile) SubmoduleWebLink(ctx context.Context, optCommitID } if !sf.parsed { sf.parsed = true - parsedURL, err := giturl.ParseRepositoryURL(ctx, sf.refURL) - if err != nil { - return nil + if strings.HasPrefix(sf.refURL, "../") { + sf.repoLink = sf.refURL + } else { + parsedURL, err := giturl.ParseRepositoryURL(ctx, sf.refURL) + if err != nil { + return nil + } + sf.repoLink = giturl.MakeRepositoryWebLink(parsedURL) } - sf.parsedURL = parsedURL - sf.repoLink = giturl.MakeRepositoryWebLink(sf.parsedURL) } var commitLink string if len(optCommitID) == 2 { diff --git a/modules/git/commit_submodule_file_test.go b/modules/git/commit_submodule_file_test.go index 6581fa871276a..103e55e920ec3 100644 --- a/modules/git/commit_submodule_file_test.go +++ b/modules/git/commit_submodule_file_test.go @@ -10,20 +10,29 @@ import ( ) func TestCommitSubmoduleLink(t *testing.T) { - sf := NewCommitSubmoduleFile("git@github.com:user/repo.git", "aaaa") + wl := (*CommitSubmoduleFile)(nil).SubmoduleWebLink(t.Context()) + assert.Nil(t, wl) - wl := sf.SubmoduleWebLink(t.Context()) - assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink) - assert.Equal(t, "https://github.com/user/repo/tree/aaaa", wl.CommitWebLink) + t.Run("GitHubRepo", func(t *testing.T) { + sf := NewCommitSubmoduleFile("git@github.com:user/repo.git", "aaaa") - wl = sf.SubmoduleWebLink(t.Context(), "1111") - assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink) - assert.Equal(t, "https://github.com/user/repo/tree/1111", wl.CommitWebLink) + wl := sf.SubmoduleWebLink(t.Context()) + assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink) + assert.Equal(t, "https://github.com/user/repo/tree/aaaa", wl.CommitWebLink) - 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/compare/1111...2222", wl.CommitWebLink) + wl = sf.SubmoduleWebLink(t.Context(), "1111") + assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink) + assert.Equal(t, "https://github.com/user/repo/tree/1111", wl.CommitWebLink) - wl = (*CommitSubmoduleFile)(nil).SubmoduleWebLink(t.Context()) - assert.Nil(t, wl) + 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/compare/1111...2222", wl.CommitWebLink) + }) + + t.Run("RelativePath", func(t *testing.T) { + 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) + }) } diff --git a/web_src/css/repo/home-file-list.css b/web_src/css/repo/home-file-list.css index f2ab052a54cf2..0f5cf82ad4e6e 100644 --- a/web_src/css/repo/home-file-list.css +++ b/web_src/css/repo/home-file-list.css @@ -71,7 +71,7 @@ #repo-files-table .repo-file-cell.name .entry-name { flex-shrink: 1; - min-width: 3em; + min-width: 4px; /* leave about one letter space when shrinking */ } @media (max-width: 767.98px) { From d5313890a1f9c18052ea74c161c75a04f7be7742 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 10 Jul 2025 21:49:30 +0800 Subject: [PATCH 2/4] use 1ch and add more comments --- web_src/css/repo/home-file-list.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/css/repo/home-file-list.css b/web_src/css/repo/home-file-list.css index 0f5cf82ad4e6e..6aa9e4bca3d2e 100644 --- a/web_src/css/repo/home-file-list.css +++ b/web_src/css/repo/home-file-list.css @@ -71,7 +71,7 @@ #repo-files-table .repo-file-cell.name .entry-name { flex-shrink: 1; - min-width: 4px; /* leave about one letter space when shrinking */ + 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) { From 766baa6b8b6bc4e4f577c9602a4184c6a7260998 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 10 Jul 2025 22:15:37 +0800 Subject: [PATCH 3/4] add FIXME --- modules/git/commit_submodule_file.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/git/commit_submodule_file.go b/modules/git/commit_submodule_file.go index 08a8c3ff4d0e3..3a26451039735 100644 --- a/modules/git/commit_submodule_file.go +++ b/modules/git/commit_submodule_file.go @@ -36,6 +36,11 @@ func (sf *CommitSubmoduleFile) SubmoduleWebLink(ctx context.Context, optCommitID if !sf.parsed { 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 + // 2. Resolve the relative path based on submodule's full path, and still keep the unresolved relative path + // 3. Resolve the unresolved relative path based on the current repository's URL + // Not an easy task and need to refactor related code a lot. sf.repoLink = sf.refURL } else { parsedURL, err := giturl.ParseRepositoryURL(ctx, sf.refURL) From 540dff852702b473e8a61555f4ecb7c56050ff12 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 10 Jul 2025 22:40:11 +0800 Subject: [PATCH 4/4] improve FIXME --- modules/git/commit_submodule_file.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/git/commit_submodule_file.go b/modules/git/commit_submodule_file.go index 3a26451039735..5def80f3bdc85 100644 --- a/modules/git/commit_submodule_file.go +++ b/modules/git/commit_submodule_file.go @@ -13,10 +13,11 @@ import ( // CommitSubmoduleFile represents a file with submodule type. type CommitSubmoduleFile struct { - refURL string - parsed bool - refID string - repoLink string + refURL string + refID string + + parsed bool + targetRepoLink string } // NewCommitSubmoduleFile create a new submodule file @@ -37,26 +38,25 @@ func (sf *CommitSubmoduleFile) SubmoduleWebLink(ctx context.Context, optCommitID 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 - // 2. Resolve the relative path based on submodule's full path, and still keep the unresolved relative path - // 3. Resolve the unresolved relative path based on the current repository's URL + // 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.repoLink = sf.refURL + sf.targetRepoLink = sf.refURL } else { parsedURL, err := giturl.ParseRepositoryURL(ctx, sf.refURL) if err != nil { return nil } - sf.repoLink = giturl.MakeRepositoryWebLink(parsedURL) + sf.targetRepoLink = giturl.MakeRepositoryWebLink(parsedURL) } } var commitLink string 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 { - commitLink = sf.repoLink + "/tree/" + optCommitID[0] + commitLink = sf.targetRepoLink + "/tree/" + optCommitID[0] } 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} }