Compare commits

..

4 Commits

Author SHA1 Message Date
silverwind
3531e9dbfd Replace setup-python with setup-uv (#35116)
Some checks failed
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-docker-rootful (push) Has been cancelled
release-nightly / nightly-docker-rootless (push) Has been cancelled
cron-translations / crowdin-pull (push) Has been cancelled
2025-07-18 14:02:57 +00:00
wxiaoguang
c4f5b2b531 Don't use full-file highlight when there is a git diff textconv (#35114)
Fix #35106
2025-07-18 19:16:27 +08:00
wxiaoguang
8f91bfe9d8 Fix submodule parsing when the gitmodules is missing (#35109)
Follow up #35096, fix #35095, fix #35115 and add more tests

The old code used some fragile behaviors which depend on the "nil"
receiver. This PR should be a complete fix for more edge cases.
2025-07-18 09:42:44 +00:00
silverwind
13b9659952 Align issue-title-buttons with list-header (#35018)
This change concerns the "Edit" and "New Issue" button on top right.
With this change, switching from the issue list into an issue, the "New
Issue" button will no longer "shift" from the postion on the previous
page.

<img width="1299" alt="Screenshot 2025-07-09 at 17 37 31"
src="https://github.com/user-attachments/assets/1ea55d8a-2abd-49b0-951a-ccc6466a74ee"
/>

<img width="1300" alt="Screenshot 2025-07-09 at 17 37 19"
src="https://github.com/user-attachments/assets/05997d9d-25eb-4786-803d-00c575f78bef"
/>

---------

Signed-off-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-07-18 09:13:32 +00:00
10 changed files with 40 additions and 29 deletions

View File

@@ -32,15 +32,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: astral-sh/setup-uv@v6
- run: uv python install 3.12
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
cache-dependency-path: package-lock.json
- run: pip install uv
- run: make deps-py
- run: make deps-frontend
- run: make lint-templates
@@ -51,10 +49,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install uv
- uses: astral-sh/setup-uv@v6
- run: uv python install 3.12
- run: make deps-py
- run: make lint-yaml

View File

@@ -20,6 +20,7 @@ const (
GitlabLanguage = "gitlab-language"
Lockable = "lockable"
Filter = "filter"
Diff = "diff"
)
var LinguistAttributes = []string{

View File

@@ -15,8 +15,12 @@ type CommitInfo struct {
func getCommitInfoSubmoduleFile(repoLink string, entry *TreeEntry, commit *Commit, treePathDir string) (*CommitSubmoduleFile, error) {
fullPath := path.Join(treePathDir, entry.Name())
submodule, err := commit.GetSubModule(fullPath)
if submodule == nil || err != nil {
if err != nil {
return nil, err
}
if submodule == nil {
// unable to find submodule from ".gitmodules" file
return NewCommitSubmoduleFile(repoLink, fullPath, "", entry.ID.String()), nil
}
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, entry.ID.String()), nil
}

View File

@@ -129,7 +129,14 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
require.NoError(t, err)
cisf, err := getCommitInfoSubmoduleFile("/any/repo-link", tree, commit, "")
require.NoError(t, err)
assert.Nil(t, cisf)
assert.Equal(t, &CommitSubmoduleFile{
repoLink: "/any/repo-link",
fullPath: "file1.txt",
refURL: "",
refID: "e2129701f1a4d54dc44f03c93bca0a2aec7c5449",
}, cisf)
// since there is no refURL, it means that the submodule info doesn't exist, so it won't have a web link
assert.Nil(t, cisf.SubmoduleWebLinkTree(t.Context()))
})
}

View File

@@ -29,12 +29,16 @@ func NewCommitSubmoduleFile(repoLink, fullPath, refURL, refID string) *CommitSub
return &CommitSubmoduleFile{repoLink: repoLink, fullPath: fullPath, refURL: refURL, refID: refID}
}
// RefID returns the commit ID of the submodule, it returns empty string for nil receiver
func (sf *CommitSubmoduleFile) RefID() string {
if sf == nil {
return ""
}
return sf.refID
}
func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreLinkPath string) *SubmoduleWebLink {
if sf == nil {
if sf == nil || sf.refURL == "" {
return nil
}
if strings.HasPrefix(sf.refURL, "../") {
@@ -53,14 +57,13 @@ func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreL
}
// SubmoduleWebLinkTree tries to make the submodule's tree link in its own repo, it also works on "nil" receiver
// It returns nil if the submodule does not have a valid URL or is nil
func (sf *CommitSubmoduleFile) SubmoduleWebLinkTree(ctx context.Context, optCommitID ...string) *SubmoduleWebLink {
if sf == nil {
return nil
}
return sf.getWebLinkInTargetRepo(ctx, "/tree/"+util.OptionalArg(optCommitID, sf.refID))
return sf.getWebLinkInTargetRepo(ctx, "/tree/"+util.OptionalArg(optCommitID, sf.RefID()))
}
// SubmoduleWebLinkCompare tries to make the submodule's compare link in its own repo, it also works on "nil" receiver
// It returns nil if the submodule does not have a valid URL or is nil
func (sf *CommitSubmoduleFile) SubmoduleWebLinkCompare(ctx context.Context, commitID1, commitID2 string) *SubmoduleWebLink {
return sf.getWebLinkInTargetRepo(ctx, "/compare/"+commitID1+"..."+commitID2)
}

View File

@@ -12,6 +12,8 @@ import (
func TestCommitSubmoduleLink(t *testing.T) {
assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkTree(t.Context()))
assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkCompare(t.Context(), "", ""))
assert.Nil(t, (&CommitSubmoduleFile{}).SubmoduleWebLinkTree(t.Context()))
assert.Nil(t, (&CommitSubmoduleFile{}).SubmoduleWebLinkCompare(t.Context(), "", ""))
t.Run("GitHubRepo", func(t *testing.T) {
sf := NewCommitSubmoduleFile("/any/repo-link", "full-path", "git@github.com:user/repo.git", "aaaa")

View File

@@ -259,9 +259,10 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
}
func handleRepoViewSubmodule(ctx *context.Context, submodule *git.SubModule) {
// TODO: it needs to use git.NewCommitSubmoduleFile and SubmoduleWebLinkTree to correctly handle relative paths
submoduleRepoURL, err := giturl.ParseRepositoryURL(ctx, submodule.URL)
if err != nil {
HandleGitError(ctx, "prepareToRenderDirOrFile: ParseRepositoryURL", err)
HandleGitError(ctx, "handleRepoViewSubmodule: ParseRepositoryURL", err)
return
}
submoduleURL := giturl.MakeRepositoryWebLink(submoduleRepoURL)

View File

@@ -1191,7 +1191,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
return nil, err
}
checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage})
checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage, attribute.Diff})
if err != nil {
return nil, err
}
@@ -1200,6 +1200,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
for _, diffFile := range diff.Files {
isVendored := optional.None[bool]()
isGenerated := optional.None[bool]()
attrDiff := optional.None[string]()
attrs, err := checker.CheckPath(diffFile.Name)
if err == nil {
isVendored, isGenerated = attrs.GetVendored(), attrs.GetGenerated()
@@ -1207,6 +1208,7 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
if language.Has() {
diffFile.Language = language.Value()
}
attrDiff = attrs.Get(attribute.Diff).ToString()
}
// Populate Submodule URLs
@@ -1228,7 +1230,8 @@ func GetDiffForRender(ctx context.Context, repoLink string, gitRepo *git.Reposit
diffFile.Sections = append(diffFile.Sections, tailSection)
}
if !setting.Git.DisableDiffHighlight {
shouldFullFileHighlight := !setting.Git.DisableDiffHighlight && attrDiff.Value() == ""
if shouldFullFileHighlight {
if limitedContent.LeftContent != nil && limitedContent.LeftContent.buf.Len() < MaxDiffHighlightEntireFileSize {
diffFile.highlightedLeftLines = highlightCodeLines(diffFile, true /* left */, limitedContent.LeftContent.buf.String())
}

View File

@@ -174,7 +174,9 @@ func newTreeViewNodeFromEntry(ctx context.Context, repoLink string, renderedIcon
} else if subModule != nil {
submoduleFile := git.NewCommitSubmoduleFile(repoLink, node.FullPath, subModule.URL, entry.ID.String())
webLink := submoduleFile.SubmoduleWebLinkTree(ctx)
node.SubmoduleURL = webLink.CommitWebLink
if webLink != nil {
node.SubmoduleURL = webLink.CommitWebLink
}
}
}

View File

@@ -334,7 +334,7 @@ td .commit-summary {
display: flex;
gap: 0.5em;
margin-bottom: 8px;
min-height: 40px; /* avoid layout shift on edit */
min-height: 36px; /* avoid layout shift on edit */
}
.repository.view.issue .issue-title h1 {
@@ -342,20 +342,12 @@ td .commit-summary {
width: 100%;
font-weight: var(--font-weight-normal);
font-size: 32px;
line-height: 40px;
line-height: 36px; /* vertically center single-line text with .issue-title-buttons */
margin: 0;
padding-right: 0.25rem;
overflow-wrap: anywhere;
}
.repository.view.issue .issue-title#issue-title-display .issue-title-buttons {
margin-top: 4px; /* the title's height is 40px, fine tune to align the buttons */
}
.repository.view.issue .issue-title#issue-title-editor {
padding-top: 4px;
}
@media (max-width: 767.98px) {
.repository.view.issue .issue-title {
flex-direction: column;