From 8d799c236c854c8bb132b38c97385beaf53d9327 Mon Sep 17 00:00:00 2001 From: badhezi Date: Tue, 15 Apr 2025 19:56:19 +0300 Subject: [PATCH 01/17] use the correct context data for PR link template in issue card --- templates/repo/issue/card.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/card.tmpl b/templates/repo/issue/card.tmpl index c7bbe91885012..41fe6cea8fbae 100644 --- a/templates/repo/issue/card.tmpl +++ b/templates/repo/issue/card.tmpl @@ -45,7 +45,7 @@ {{if $.Page.LinkedPRs}} {{range index $.Page.LinkedPRs .ID}}
- + {{svg "octicon-git-merge" 16 "tw-mr-1 tw-align-middle"}} {{.Title}} #{{.Index}} From f86ddd53f03b26403b5575098e24d5df9b4c2a80 Mon Sep 17 00:00:00 2001 From: badhezi Date: Mon, 12 May 2025 16:38:44 +0300 Subject: [PATCH 02/17] parse .raw and .diff optional compare parameters --- routers/api/packages/api.go | 1 - routers/common/compare.go | 1 + routers/web/repo/compare.go | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/routers/api/packages/api.go b/routers/api/packages/api.go index ae4ea7ea87afc..8e8080b6225b8 100644 --- a/routers/api/packages/api.go +++ b/routers/api/packages/api.go @@ -685,7 +685,6 @@ func CommonRoutes() *web.Router { // https://github.com/opencontainers/distribution-spec/blob/main/spec.md func ContainerRoutes() *web.Router { r := web.NewRouter() - r.Use(context.PackageContexter()) verifyAuth(r, []auth.Method{ diff --git a/routers/common/compare.go b/routers/common/compare.go index 4d1cc2f0d8908..736f73db0e0e0 100644 --- a/routers/common/compare.go +++ b/routers/common/compare.go @@ -18,4 +18,5 @@ type CompareInfo struct { BaseBranch string HeadBranch string DirectComparison bool + RawDiffType git.RawDiffType } diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 8b99dd95da109..12ce37bcef7f5 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -228,7 +228,19 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { ) infoPath = ctx.PathParam("*") + var infos []string + + // Handle possible suffixes: .diff or .patch + if strings.HasSuffix(infoPath, ".diff") { + ci.RawDiffType = git.RawDiffNormal + infoPath = strings.TrimSuffix(infoPath, ".diff") + + } else if strings.HasSuffix(infoPath, ".patch") { + ci.RawDiffType = git.RawDiffPatch + infoPath = strings.TrimSuffix(infoPath, ".patch") + } + if infoPath == "" { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} } else { @@ -743,6 +755,12 @@ func CompareDiff(ctx *context.Context) { return } + if ci.RawDiffType != "" { + git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, ci.RawDiffType, "", ctx.Resp) + ctx.Resp.Flush() + return + } + baseTags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID) if err != nil { ctx.ServerError("GetTagNamesByRepoID", err) From acb57e503129d7ef4fcba5d398d78c84d9b896b8 Mon Sep 17 00:00:00 2001 From: badhezi Date: Mon, 12 May 2025 17:07:15 +0300 Subject: [PATCH 03/17] lint, err handle --- routers/api/packages/api.go | 1 + routers/web/repo/compare.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/routers/api/packages/api.go b/routers/api/packages/api.go index 8e8080b6225b8..ae4ea7ea87afc 100644 --- a/routers/api/packages/api.go +++ b/routers/api/packages/api.go @@ -685,6 +685,7 @@ func CommonRoutes() *web.Router { // https://github.com/opencontainers/distribution-spec/blob/main/spec.md func ContainerRoutes() *web.Router { r := web.NewRouter() + r.Use(context.PackageContexter()) verifyAuth(r, []auth.Method{ diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 12ce37bcef7f5..8647033923aa8 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -235,7 +235,6 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { if strings.HasSuffix(infoPath, ".diff") { ci.RawDiffType = git.RawDiffNormal infoPath = strings.TrimSuffix(infoPath, ".diff") - } else if strings.HasSuffix(infoPath, ".patch") { ci.RawDiffType = git.RawDiffPatch infoPath = strings.TrimSuffix(infoPath, ".patch") @@ -756,7 +755,11 @@ func CompareDiff(ctx *context.Context) { } if ci.RawDiffType != "" { - git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, ci.RawDiffType, "", ctx.Resp) + err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, ci.RawDiffType, "", ctx.Resp) + if err != nil { + ctx.ServerError("GetRepoRawDiffForFile", err) + return + } ctx.Resp.Flush() return } From 180c1b075e814b0a0d32060f527a8c7ac343ca2a Mon Sep 17 00:00:00 2001 From: badhezi Date: Mon, 12 May 2025 20:29:12 +0300 Subject: [PATCH 04/17] integration tests: WIP --- tests/integration/compare_test.go | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 0648777fede0e..712328db86f10 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/test" repo_service "code.gitea.io/gitea/services/repository" "code.gitea.io/gitea/tests" @@ -158,3 +159,41 @@ func TestCompareCodeExpand(t *testing.T) { } }) } + +func TestCompareRawDiff(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + repo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user1, user1, repo_service.CreateRepoOptions{ + Name: "test_raw_diff", + Readme: "Default", + AutoInit: true, + DefaultBranch: "main", + }, true) + assert.NoError(t, err) + session := loginUser(t, user1.Name) + r, _ := gitrepo.OpenRepository(db.DefaultContext, repo) + oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) + testEditFile(t, session, user1.Name, repo.Name, "main", "README.md", strings.Repeat("a\n", 2)) + newRef, _ := r.GetBranchCommit(repo.DefaultBranch) + fmt.Println("oldRef", oldRef.ID.String()) + fmt.Println("newRef", newRef.ID.String()) + + req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s.diff", oldRef.ID.String(), newRef.ID.String())) + resp := session.MakeRequest(t, req, http.StatusOK) + fmt.Println("resp", resp.Body.String()) + + expected := fmt.Sprintf(`diff --git a/README.md b/README.md +index %s..%s 100644 +--- a/README.md ++++ b/README.md +@@ -1,2 +1,2 @@ +-# test_raw_diff +- ++a ++a +`, + oldRef.ID.String()[:7], newRef.ID.String()[:7]) + + assert.Equal(t, resp.Body.String(), expected) + }) +} From 2bcb546ca3a8e3e2463c9de328595899a6db3159 Mon Sep 17 00:00:00 2001 From: badhezi Date: Tue, 13 May 2025 22:30:24 +0300 Subject: [PATCH 05/17] Add tests and RevParse() function --- modules/git/tree.go | 11 +++++ tests/integration/compare_test.go | 73 ++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/modules/git/tree.go b/modules/git/tree.go index f6fdff97d0400..8e04b721fa760 100644 --- a/modules/git/tree.go +++ b/modules/git/tree.go @@ -73,3 +73,14 @@ func (repo *Repository) GetTreePathLatestCommit(refName, treePath string) (*Comm } return repo.GetCommit(strings.TrimSpace(stdout)) } + +// rev-parse parses the output of `git rev-parse` command +func (repo *Repository) RevParse(ref string, file string) (string, error) { + stdout, _, err := NewCommand("rev-parse"). + AddDynamicArguments(ref+":"+file). + RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path}) + if err != nil { + return "", err + } + return strings.TrimSpace(stdout), nil +} diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 712328db86f10..634a6b565236d 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -9,6 +9,7 @@ import ( "net/url" "strings" "testing" + "time" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" @@ -160,7 +161,7 @@ func TestCompareCodeExpand(t *testing.T) { }) } -func TestCompareRawDiff(t *testing.T) { +func TestCompareRawDiffNormal(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) repo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user1, user1, repo_service.CreateRepoOptions{ @@ -171,16 +172,19 @@ func TestCompareRawDiff(t *testing.T) { }, true) assert.NoError(t, err) session := loginUser(t, user1.Name) + r, _ := gitrepo.OpenRepository(db.DefaultContext, repo) + oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) + oldBlobRef, _ := r.RevParse(oldRef.ID.String(), "README.md") + testEditFile(t, session, user1.Name, repo.Name, "main", "README.md", strings.Repeat("a\n", 2)) + newRef, _ := r.GetBranchCommit(repo.DefaultBranch) - fmt.Println("oldRef", oldRef.ID.String()) - fmt.Println("newRef", newRef.ID.String()) + newBlobRef, _ := r.RevParse(newRef.ID.String(), "README.md") req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s.diff", oldRef.ID.String(), newRef.ID.String())) resp := session.MakeRequest(t, req, http.StatusOK) - fmt.Println("resp", resp.Body.String()) expected := fmt.Sprintf(`diff --git a/README.md b/README.md index %s..%s 100644 @@ -191,9 +195,64 @@ index %s..%s 100644 - +a +a -`, - oldRef.ID.String()[:7], newRef.ID.String()[:7]) +`, oldBlobRef[:7], newBlobRef[:7]) + assert.Equal(t, expected, resp.Body.String()) + }) +} + +func TestCompareRawDiffPatch(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + repo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user1, user1, repo_service.CreateRepoOptions{ + Name: "test_raw_diff", + Readme: "Default", + AutoInit: true, + DefaultBranch: "main", + }, true) + assert.NoError(t, err) + session := loginUser(t, user1.Name) + + r, _ := gitrepo.OpenRepository(db.DefaultContext, repo) - assert.Equal(t, resp.Body.String(), expected) + // Get the old commit and blob reference + oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) + oldBlobRef, _ := r.RevParse(oldRef.ID.String(), "README.md") + + resp := testEditFile(t, session, user1.Name, repo.Name, "main", "README.md", strings.Repeat("a\n", 2)) + + newRef, _ := r.GetBranchCommit(repo.DefaultBranch) + newBlobRef, _ := r.RevParse(newRef.ID.String(), "README.md") + + // Get the last modified time from the response header + respTs, _ := time.Parse(time.RFC1123, resp.Result().Header.Get("Last-Modified")) + respTs = respTs.In(time.Local) + + // Format the timestamp to match the expected format in the patch + customFormat := "Mon, 02 Jan 2006 15:04:05" + respTsStr := respTs.Format(customFormat) + + req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s.patch", oldRef.ID.String(), newRef.ID.String())) + resp = session.MakeRequest(t, req, http.StatusOK) + + expected := fmt.Sprintf(`From %s Mon Sep 17 00:00:00 2001 +From: User One +Date: %s +0300 +Subject: [PATCH] Update README.md + +--- + README.md | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/README.md b/README.md +index %s..%s 100644 +--- a/README.md ++++ b/README.md +@@ -1,2 +1,2 @@ +-# test_raw_diff +- ++a ++a +`, newRef.ID.String(), respTsStr, oldBlobRef[:7], newBlobRef[:7]) + assert.Equal(t, expected, resp.Body.String()) }) } From a9c8ce990e9bfaf29a34596c402bf352a9664790 Mon Sep 17 00:00:00 2001 From: badhezi Date: Tue, 13 May 2025 22:54:09 +0300 Subject: [PATCH 06/17] formatting --- modules/git/tree.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/git/tree.go b/modules/git/tree.go index 8e04b721fa760..ac87e3259bb73 100644 --- a/modules/git/tree.go +++ b/modules/git/tree.go @@ -75,7 +75,7 @@ func (repo *Repository) GetTreePathLatestCommit(refName, treePath string) (*Comm } // rev-parse parses the output of `git rev-parse` command -func (repo *Repository) RevParse(ref string, file string) (string, error) { +func (repo *Repository) RevParse(ref, file string) (string, error) { stdout, _, err := NewCommand("rev-parse"). AddDynamicArguments(ref+":"+file). RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path}) From 17c860e97d32e73515d0adbb1fcc24b24d1c046c Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 14 May 2025 12:22:35 +0300 Subject: [PATCH 07/17] fix timezone adjustment in TestCompareRawDiffPatch --- tests/integration/compare_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 634a6b565236d..6aefbd0e40c55 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -228,7 +228,7 @@ func TestCompareRawDiffPatch(t *testing.T) { respTs = respTs.In(time.Local) // Format the timestamp to match the expected format in the patch - customFormat := "Mon, 02 Jan 2006 15:04:05" + customFormat := "Mon, 02 Jan 2006 15:04:05 -0700" respTsStr := respTs.Format(customFormat) req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s.patch", oldRef.ID.String(), newRef.ID.String())) @@ -236,7 +236,7 @@ func TestCompareRawDiffPatch(t *testing.T) { expected := fmt.Sprintf(`From %s Mon Sep 17 00:00:00 2001 From: User One -Date: %s +0300 +Date: %s Subject: [PATCH] Update README.md --- From 3274b844c69f99a34505e61037fc34fd67594aaf Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 14 May 2025 13:59:51 +0300 Subject: [PATCH 08/17] support tag and branch names with ends with .diff and .patch --- routers/web/repo/compare.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 8647033923aa8..989691a5720ab 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -231,18 +231,28 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { var infos []string - // Handle possible suffixes: .diff or .patch - if strings.HasSuffix(infoPath, ".diff") { - ci.RawDiffType = git.RawDiffNormal - infoPath = strings.TrimSuffix(infoPath, ".diff") - } else if strings.HasSuffix(infoPath, ".patch") { - ci.RawDiffType = git.RawDiffPatch - infoPath = strings.TrimSuffix(infoPath, ".patch") - } - if infoPath == "" { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} } else { + // check if head is a branch or tag on ly infoPath ends with .diff or .patch + if strings.HasSuffix(infoPath, ".diff") || strings.HasSuffix(infoPath, ".patch") { + infos = strings.SplitN(infoPath, "...", 2) + if len(infos) != 2 { + infos = strings.SplitN(infoPath, "..", 2) // match github behavior + } + ref2IsBranch := gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, infos[1]) + ref2IsTag := gitrepo.IsTagExist(ctx, ctx.Repo.Repository, infos[1]) + if !ref2IsBranch && !ref2IsTag { + if strings.HasSuffix(infoPath, ".diff") { + ci.RawDiffType = git.RawDiffNormal + infoPath = strings.TrimSuffix(infoPath, ".diff") + } else if strings.HasSuffix(infoPath, ".patch") { + ci.RawDiffType = git.RawDiffPatch + infoPath = strings.TrimSuffix(infoPath, ".patch") + } + } + } + infos = strings.SplitN(infoPath, "...", 2) if len(infos) != 2 { if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 { From d784a0f25d81ac8b8a3752d3feb07982f0a84b44 Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 14 May 2025 14:53:38 +0300 Subject: [PATCH 09/17] add download links to raw diff and patch in diff box options dropdown --- routers/web/repo/compare.go | 1 + templates/repo/diff/options_dropdown.tmpl | 3 +++ 2 files changed, 4 insertions(+) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 989691a5720ab..a206f8deb612f 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -750,6 +750,7 @@ func CompareDiff(ctx *context.Context) { return } + ctx.Data["PageIsCompareDiff"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes ctx.Data["DirectComparison"] = ci.DirectComparison ctx.Data["OtherCompareSeparator"] = ".." diff --git a/templates/repo/diff/options_dropdown.tmpl b/templates/repo/diff/options_dropdown.tmpl index 8d08e7ad46021..a8a6c2ac10cca 100644 --- a/templates/repo/diff/options_dropdown.tmpl +++ b/templates/repo/diff/options_dropdown.tmpl @@ -10,6 +10,9 @@ {{else if .Commit.ID.String}} {{ctx.Locale.Tr "repo.diff.download_patch"}} {{ctx.Locale.Tr "repo.diff.download_diff"}} + {{else if $.PageIsCompareDiff }} + {{ctx.Locale.Tr "repo.diff.download_patch"}} + {{ctx.Locale.Tr "repo.diff.download_diff"}} {{end}} {{ctx.Locale.Tr "repo.pulls.expand_files"}} {{ctx.Locale.Tr "repo.pulls.collapse_files"}} From c80f0b9d46e95fde2a78bafcafd6ca4efa74de1d Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 14 May 2025 15:18:18 +0300 Subject: [PATCH 10/17] fix lint and typos --- modules/git/tree.go | 2 +- routers/web/repo/compare.go | 2 +- templates/repo/diff/options_dropdown.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/git/tree.go b/modules/git/tree.go index ac87e3259bb73..9135a1edc918c 100644 --- a/modules/git/tree.go +++ b/modules/git/tree.go @@ -74,7 +74,7 @@ func (repo *Repository) GetTreePathLatestCommit(refName, treePath string) (*Comm return repo.GetCommit(strings.TrimSpace(stdout)) } -// rev-parse parses the output of `git rev-parse` command +// RevParse resolves a revision reference to other git-related objects func (repo *Repository) RevParse(ref, file string) (string, error) { stdout, _, err := NewCommand("rev-parse"). AddDynamicArguments(ref+":"+file). diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index a206f8deb612f..351236ac29f3d 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -234,7 +234,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { if infoPath == "" { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} } else { - // check if head is a branch or tag on ly infoPath ends with .diff or .patch + // check if head is a branch or tag only if infoPath ends with .diff or .patch if strings.HasSuffix(infoPath, ".diff") || strings.HasSuffix(infoPath, ".patch") { infos = strings.SplitN(infoPath, "...", 2) if len(infos) != 2 { diff --git a/templates/repo/diff/options_dropdown.tmpl b/templates/repo/diff/options_dropdown.tmpl index a8a6c2ac10cca..03519165db6dc 100644 --- a/templates/repo/diff/options_dropdown.tmpl +++ b/templates/repo/diff/options_dropdown.tmpl @@ -10,7 +10,7 @@ {{else if .Commit.ID.String}} {{ctx.Locale.Tr "repo.diff.download_patch"}} {{ctx.Locale.Tr "repo.diff.download_diff"}} - {{else if $.PageIsCompareDiff }} + {{else if $.PageIsCompareDiff}} {{ctx.Locale.Tr "repo.diff.download_patch"}} {{ctx.Locale.Tr "repo.diff.download_diff"}} {{end}} From e9fac73bcfd651aa55a7382b43803cb3deb19db9 Mon Sep 17 00:00:00 2001 From: badhezi Date: Thu, 29 May 2025 16:04:16 +0300 Subject: [PATCH 11/17] cover all head ref format cases --- routers/web/repo/compare.go | 49 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 351236ac29f3d..4f0f6341c1278 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -234,25 +234,6 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { if infoPath == "" { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} } else { - // check if head is a branch or tag only if infoPath ends with .diff or .patch - if strings.HasSuffix(infoPath, ".diff") || strings.HasSuffix(infoPath, ".patch") { - infos = strings.SplitN(infoPath, "...", 2) - if len(infos) != 2 { - infos = strings.SplitN(infoPath, "..", 2) // match github behavior - } - ref2IsBranch := gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, infos[1]) - ref2IsTag := gitrepo.IsTagExist(ctx, ctx.Repo.Repository, infos[1]) - if !ref2IsBranch && !ref2IsTag { - if strings.HasSuffix(infoPath, ".diff") { - ci.RawDiffType = git.RawDiffNormal - infoPath = strings.TrimSuffix(infoPath, ".diff") - } else if strings.HasSuffix(infoPath, ".patch") { - ci.RawDiffType = git.RawDiffPatch - infoPath = strings.TrimSuffix(infoPath, ".patch") - } - } - } - infos = strings.SplitN(infoPath, "...", 2) if len(infos) != 2 { if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 { @@ -273,7 +254,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { if len(headInfos) == 1 { isSameRepo = true ci.HeadUser = ctx.Repo.Owner - ci.HeadBranch = headInfos[0] + ci.HeadBranch = parseRefForRawDiff(ctx, ci, headInfos[0]) } else if len(headInfos) == 2 { headInfosSplit := strings.Split(headInfos[0], "/") if len(headInfosSplit) == 1 { @@ -286,7 +267,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { } return nil } - ci.HeadBranch = headInfos[1] + ci.HeadBranch = parseRefForRawDiff(ctx, ci, headInfos[1]) isSameRepo = ci.HeadUser.ID == ctx.Repo.Owner.ID if isSameRepo { ci.HeadRepo = baseRepo @@ -309,7 +290,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { } return nil } - ci.HeadBranch = headInfos[1] + ci.HeadBranch = parseRefForRawDiff(ctx, ci, headInfos[1]) ci.HeadUser = ci.HeadRepo.Owner isSameRepo = ci.HeadRepo.ID == ctx.Repo.Repository.ID } @@ -317,6 +298,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { ctx.NotFound(nil) return nil } + ctx.Data["HeadUser"] = ci.HeadUser ctx.Data["HeadBranch"] = ci.HeadBranch ctx.Repo.PullRequest.SameRepo = isSameRepo @@ -1016,3 +998,26 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu } return diffLines, nil } + +func parseRefForRawDiff(ctx *context.Context, ci *common.CompareInfo, ref string) string { + if strings.HasSuffix(ref, ".diff") || strings.HasSuffix(ref, ".patch") { + var headRepo *repo_model.Repository + if ci.HeadRepo != nil { + headRepo = ci.HeadRepo + } else { + headRepo = ctx.Repo.Repository + } + ref2IsBranch := gitrepo.IsBranchExist(ctx, headRepo, ref) + ref2IsTag := gitrepo.IsTagExist(ctx, headRepo, ref) + if !ref2IsBranch && !ref2IsTag { + if strings.HasSuffix(ref, ".diff") { + ci.RawDiffType = git.RawDiffNormal + ref = strings.TrimSuffix(ref, ".diff") + } else if strings.HasSuffix(ref, ".patch") { + ci.RawDiffType = git.RawDiffPatch + ref = strings.TrimSuffix(ref, ".patch") + } + } + } + return ref +} From 2905d354fc26580caccd6ee6eaca491a79447cd3 Mon Sep 17 00:00:00 2001 From: badhezi Date: Fri, 30 May 2025 12:58:16 +0300 Subject: [PATCH 12/17] add more test cases to cover different compare patterns --- tests/integration/compare_test.go | 102 ++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 6aefbd0e40c55..149fc08ac0a27 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -256,3 +256,105 @@ index %s..%s 100644 assert.Equal(t, expected, resp.Body.String()) }) } + +func TestCompareRawDiffNormalSameOwnerDifferentRepo(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + repo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user1, user1, repo_service.CreateRepoOptions{ + Name: "test_raw_diff", + Readme: "Default", + AutoInit: true, + DefaultBranch: "main", + }, true) + assert.NoError(t, err) + session := loginUser(t, user1.Name) + + headRepo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user1, user1, repo_service.CreateRepoOptions{ + Name: "test_raw_diff_head", + Readme: "Default", + AutoInit: true, + DefaultBranch: "main", + }, true) + assert.NoError(t, err) + + r, _ := gitrepo.OpenRepository(db.DefaultContext, repo) + hr, _ := gitrepo.OpenRepository(db.DefaultContext, headRepo) + + oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) + oldBlobRef, _ := r.RevParse(oldRef.ID.String(), "README.md") + + testEditFile(t, session, user1.Name, headRepo.Name, "main", "README.md", strings.Repeat("a\n", 2)) + + newRef, _ := hr.GetBranchCommit(headRepo.DefaultBranch) + newBlobRef, _ := hr.RevParse(newRef.ID.String(), "README.md") + + req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s/%s:%s.diff", oldRef.ID.String(), user1.LowerName, headRepo.LowerName, newRef.ID.String())) + resp := session.MakeRequest(t, req, http.StatusOK) + + expected := fmt.Sprintf(`diff --git a/README.md b/README.md +index %s..%s 100644 +--- a/README.md ++++ b/README.md +@@ -1,2 +1,2 @@ +-# test_raw_diff +- ++a ++a +`, oldBlobRef[:7], newBlobRef[:7]) + assert.Equal(t, expected, resp.Body.String()) + }) +} + +func TestCompareRawDiffNormalAcrossForks(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + + repo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user1, user1, repo_service.CreateRepoOptions{ + Name: "test_raw_diff", + Readme: "Default", + AutoInit: true, + DefaultBranch: "main", + }, true) + assert.NoError(t, err) + + headRepo, err := repo_service.ForkRepository(db.DefaultContext, user2, user2, repo_service.ForkRepoOptions{ + BaseRepo: repo, + Name: repo.Name, + Description: repo.Description, + SingleBranch: "", + }) + assert.NoError(t, err) + + session := loginUser(t, user2.Name) + + r, _ := gitrepo.OpenRepository(db.DefaultContext, repo) + hr, _ := gitrepo.OpenRepository(db.DefaultContext, headRepo) + + oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) + oldBlobRef, _ := r.RevParse(oldRef.ID.String(), "README.md") + + testEditFile(t, session, user2.Name, headRepo.Name, "main", "README.md", strings.Repeat("a\n", 2)) + session = loginUser(t, user1.Name) + + newRef, _ := hr.GetBranchCommit(headRepo.DefaultBranch) + newBlobRef, _ := hr.RevParse(newRef.ID.String(), "README.md") + + session = loginUser(t, user1.Name) + + req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s:%s.diff", oldRef.ID.String(), user2.LowerName, newRef.ID.String())) + resp := session.MakeRequest(t, req, http.StatusOK) + + expected := fmt.Sprintf(`diff --git a/README.md b/README.md +index %s..%s 100644 +--- a/README.md ++++ b/README.md +@@ -1,2 +1,2 @@ +-# test_raw_diff +- ++a ++a +`, oldBlobRef[:7], newBlobRef[:7]) + assert.Equal(t, expected, resp.Body.String()) + }) +} From 688fc78e78bf01a8a46582c62ac2a397cc8b09e7 Mon Sep 17 00:00:00 2001 From: badhezi Date: Fri, 30 May 2025 13:05:52 +0300 Subject: [PATCH 13/17] move revParse to testing code only --- modules/git/tree.go | 11 ----------- tests/integration/compare_test.go | 29 +++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/modules/git/tree.go b/modules/git/tree.go index 9135a1edc918c..f6fdff97d0400 100644 --- a/modules/git/tree.go +++ b/modules/git/tree.go @@ -73,14 +73,3 @@ func (repo *Repository) GetTreePathLatestCommit(refName, treePath string) (*Comm } return repo.GetCommit(strings.TrimSpace(stdout)) } - -// RevParse resolves a revision reference to other git-related objects -func (repo *Repository) RevParse(ref, file string) (string, error) { - stdout, _, err := NewCommand("rev-parse"). - AddDynamicArguments(ref+":"+file). - RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path}) - if err != nil { - return "", err - } - return strings.TrimSpace(stdout), nil -} diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 149fc08ac0a27..093990f0b7fef 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + git_module "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/test" repo_service "code.gitea.io/gitea/services/repository" @@ -176,12 +177,12 @@ func TestCompareRawDiffNormal(t *testing.T) { r, _ := gitrepo.OpenRepository(db.DefaultContext, repo) oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) - oldBlobRef, _ := r.RevParse(oldRef.ID.String(), "README.md") + oldBlobRef, _ := revParse(r, oldRef.ID.String(), "README.md") testEditFile(t, session, user1.Name, repo.Name, "main", "README.md", strings.Repeat("a\n", 2)) newRef, _ := r.GetBranchCommit(repo.DefaultBranch) - newBlobRef, _ := r.RevParse(newRef.ID.String(), "README.md") + newBlobRef, _ := revParse(r, newRef.ID.String(), "README.md") req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s.diff", oldRef.ID.String(), newRef.ID.String())) resp := session.MakeRequest(t, req, http.StatusOK) @@ -216,12 +217,12 @@ func TestCompareRawDiffPatch(t *testing.T) { // Get the old commit and blob reference oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) - oldBlobRef, _ := r.RevParse(oldRef.ID.String(), "README.md") + oldBlobRef, _ := revParse(r, oldRef.ID.String(), "README.md") resp := testEditFile(t, session, user1.Name, repo.Name, "main", "README.md", strings.Repeat("a\n", 2)) newRef, _ := r.GetBranchCommit(repo.DefaultBranch) - newBlobRef, _ := r.RevParse(newRef.ID.String(), "README.md") + newBlobRef, _ := revParse(r, newRef.ID.String(), "README.md") // Get the last modified time from the response header respTs, _ := time.Parse(time.RFC1123, resp.Result().Header.Get("Last-Modified")) @@ -281,12 +282,12 @@ func TestCompareRawDiffNormalSameOwnerDifferentRepo(t *testing.T) { hr, _ := gitrepo.OpenRepository(db.DefaultContext, headRepo) oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) - oldBlobRef, _ := r.RevParse(oldRef.ID.String(), "README.md") + oldBlobRef, _ := revParse(r, oldRef.ID.String(), "README.md") testEditFile(t, session, user1.Name, headRepo.Name, "main", "README.md", strings.Repeat("a\n", 2)) newRef, _ := hr.GetBranchCommit(headRepo.DefaultBranch) - newBlobRef, _ := hr.RevParse(newRef.ID.String(), "README.md") + newBlobRef, _ := revParse(hr, newRef.ID.String(), "README.md") req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s/%s:%s.diff", oldRef.ID.String(), user1.LowerName, headRepo.LowerName, newRef.ID.String())) resp := session.MakeRequest(t, req, http.StatusOK) @@ -332,13 +333,13 @@ func TestCompareRawDiffNormalAcrossForks(t *testing.T) { hr, _ := gitrepo.OpenRepository(db.DefaultContext, headRepo) oldRef, _ := r.GetBranchCommit(repo.DefaultBranch) - oldBlobRef, _ := r.RevParse(oldRef.ID.String(), "README.md") + oldBlobRef, _ := revParse(r, oldRef.ID.String(), "README.md") testEditFile(t, session, user2.Name, headRepo.Name, "main", "README.md", strings.Repeat("a\n", 2)) session = loginUser(t, user1.Name) newRef, _ := hr.GetBranchCommit(headRepo.DefaultBranch) - newBlobRef, _ := hr.RevParse(newRef.ID.String(), "README.md") + newBlobRef, _ := revParse(hr, newRef.ID.String(), "README.md") session = loginUser(t, user1.Name) @@ -358,3 +359,15 @@ index %s..%s 100644 assert.Equal(t, expected, resp.Body.String()) }) } + +// helper function to use rev-parse +// revParse resolves a revision reference to other git-related objects +func revParse(repo *git_module.Repository, ref, file string) (string, error) { + stdout, _, err := git_module.NewCommand("rev-parse"). + AddDynamicArguments(ref+":"+file). + RunStdString(repo.Ctx, &git_module.RunOpts{Dir: repo.Path}) + if err != nil { + return "", err + } + return strings.TrimSpace(stdout), nil +} From b9102f532e822d2a41c1887e0b15bbab52e023cf Mon Sep 17 00:00:00 2001 From: badhezi Date: Fri, 30 May 2025 13:17:16 +0300 Subject: [PATCH 14/17] remove redundant line --- tests/integration/compare_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 093990f0b7fef..f0304de9b75a3 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -336,7 +336,6 @@ func TestCompareRawDiffNormalAcrossForks(t *testing.T) { oldBlobRef, _ := revParse(r, oldRef.ID.String(), "README.md") testEditFile(t, session, user2.Name, headRepo.Name, "main", "README.md", strings.Repeat("a\n", 2)) - session = loginUser(t, user1.Name) newRef, _ := hr.GetBranchCommit(headRepo.DefaultBranch) newBlobRef, _ := revParse(hr, newRef.ID.String(), "README.md") From e442ab15b146739daa89c48973d51478b9d8e030 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 1 Jun 2025 23:30:44 +0800 Subject: [PATCH 15/17] revert unnecessary change --- routers/web/repo/compare.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 4f0f6341c1278..9cd463a4fea6f 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -228,9 +228,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { ) infoPath = ctx.PathParam("*") - var infos []string - if infoPath == "" { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} } else { @@ -298,7 +296,6 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { ctx.NotFound(nil) return nil } - ctx.Data["HeadUser"] = ci.HeadUser ctx.Data["HeadBranch"] = ci.HeadBranch ctx.Repo.PullRequest.SameRepo = isSameRepo From 180386b0d67d523372e4b64e99b0ddeed4563f59 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 1 Jun 2025 23:48:39 +0800 Subject: [PATCH 16/17] FIXME: how to correctly choose the head repository? --- routers/web/repo/compare.go | 54 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 9cd463a4fea6f..846064b4166d0 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -221,13 +221,9 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { // base<-head: master...head:feature // same repo: master...feature - var ( - isSameRepo bool - infoPath string - err error - ) + var isSameRepo bool - infoPath = ctx.PathParam("*") + infoPath := ctx.PathParam("*") var infos []string if infoPath == "" { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch} @@ -247,12 +243,14 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { ci.BaseBranch = infos[0] ctx.Data["BaseBranch"] = ci.BaseBranch - // If there is no head repository, it means compare between same repository. + var err error + + // If there is no head repository, it means compare between the same repository. headInfos := strings.Split(infos[1], ":") if len(headInfos) == 1 { isSameRepo = true ci.HeadUser = ctx.Repo.Owner - ci.HeadBranch = parseRefForRawDiff(ctx, ci, headInfos[0]) + ci.HeadBranch, ci.RawDiffType = parseRefForRawDiff(ctx, ctx.Repo.Repository, headInfos[0]) } else if len(headInfos) == 2 { headInfosSplit := strings.Split(headInfos[0], "/") if len(headInfosSplit) == 1 { @@ -265,7 +263,8 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { } return nil } - ci.HeadBranch = parseRefForRawDiff(ctx, ci, headInfos[1]) + // FIXME: how to correctly choose the head repository? The logic below (3-8) is quite complex, the real head repo is determined there + ci.HeadBranch, ci.RawDiffType = parseRefForRawDiff(ctx, ..., headInfos[1]) isSameRepo = ci.HeadUser.ID == ctx.Repo.Owner.ID if isSameRepo { ci.HeadRepo = baseRepo @@ -288,7 +287,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { } return nil } - ci.HeadBranch = parseRefForRawDiff(ctx, ci, headInfos[1]) + ci.HeadBranch, ci.RawDiffType = parseRefForRawDiff(ctx, ci.HeadRepo, headInfos[1]) ci.HeadUser = ci.HeadRepo.Owner isSameRepo = ci.HeadRepo.ID == ctx.Repo.Repository.ID } @@ -750,7 +749,6 @@ func CompareDiff(ctx *context.Context) { ctx.ServerError("GetRepoRawDiffForFile", err) return } - ctx.Resp.Flush() return } @@ -996,25 +994,19 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu return diffLines, nil } -func parseRefForRawDiff(ctx *context.Context, ci *common.CompareInfo, ref string) string { - if strings.HasSuffix(ref, ".diff") || strings.HasSuffix(ref, ".patch") { - var headRepo *repo_model.Repository - if ci.HeadRepo != nil { - headRepo = ci.HeadRepo - } else { - headRepo = ctx.Repo.Repository - } - ref2IsBranch := gitrepo.IsBranchExist(ctx, headRepo, ref) - ref2IsTag := gitrepo.IsTagExist(ctx, headRepo, ref) - if !ref2IsBranch && !ref2IsTag { - if strings.HasSuffix(ref, ".diff") { - ci.RawDiffType = git.RawDiffNormal - ref = strings.TrimSuffix(ref, ".diff") - } else if strings.HasSuffix(ref, ".patch") { - ci.RawDiffType = git.RawDiffPatch - ref = strings.TrimSuffix(ref, ".patch") - } - } +func parseRefForRawDiff(ctx *context.Context, refRepo *repo_model.Repository, refShortName string) (string, git.RawDiffType) { + if !strings.HasSuffix(refShortName, ".diff") && !strings.HasSuffix(refShortName, ".patch") { + return refShortName, "" + } + + if gitrepo.IsBranchExist(ctx, refRepo, refShortName) || gitrepo.IsTagExist(ctx, refRepo, refShortName) { + return refShortName, "" + } + + if s, ok := strings.CutSuffix(refShortName, ".diff"); ok { + return s, git.RawDiffNormal + } else if s, ok = strings.CutSuffix(refShortName, ".patch"); ok { + return s, git.RawDiffPatch } - return ref + return refShortName, "" } From a8ef5d5125955b6c76ef8d30d5be6221e8e0a477 Mon Sep 17 00:00:00 2001 From: badhezi Date: Mon, 2 Jun 2025 11:53:01 +0300 Subject: [PATCH 17/17] make head repo selection clearer --- routers/web/repo/compare.go | 26 ++++++++++++++++++-------- tests/integration/compare_test.go | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 846064b4166d0..7fb99925b9dab 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -247,13 +247,13 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { // If there is no head repository, it means compare between the same repository. headInfos := strings.Split(infos[1], ":") - if len(headInfos) == 1 { + if len(headInfos) == 1 { // {:headBranch} case, guaranteed baseRepo is headRepo isSameRepo = true ci.HeadUser = ctx.Repo.Owner - ci.HeadBranch, ci.RawDiffType = parseRefForRawDiff(ctx, ctx.Repo.Repository, headInfos[0]) - } else if len(headInfos) == 2 { + ci.HeadBranch, ci.RawDiffType = parseRefForRawDiff(ctx, baseRepo, headInfos[0]) + } else if len(headInfos) == 2 { // {:headOwner}:{:headBranch} or {:headOwner}/{:headRepoName}:{:headBranch} case headInfosSplit := strings.Split(headInfos[0], "/") - if len(headInfosSplit) == 1 { + if len(headInfosSplit) == 1 { // {:headOwner}:{:headBranch} case, guaranteed baseRepo.Name is headRepo.Name ci.HeadUser, err = user_model.GetUserByName(ctx, headInfos[0]) if err != nil { if user_model.IsErrUserNotExist(err) { @@ -263,13 +263,23 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { } return nil } - // FIXME: how to correctly choose the head repository? The logic below (3-8) is quite complex, the real head repo is determined there - ci.HeadBranch, ci.RawDiffType = parseRefForRawDiff(ctx, ..., headInfos[1]) + + headRepo, err := repo_model.GetRepositoryByOwnerAndName(ctx, ci.HeadUser.Name, baseRepo.Name) + if err != nil { + if repo_model.IsErrRepoNotExist(err) { + ctx.NotFound(nil) + } else { + ctx.ServerError("GetRepositoryByOwnerAndName", err) + } + return nil + } + ci.HeadBranch, ci.RawDiffType = parseRefForRawDiff(ctx, headRepo, headInfos[1]) + isSameRepo = ci.HeadUser.ID == ctx.Repo.Owner.ID - if isSameRepo { + if isSameRepo { // not a fork ci.HeadRepo = baseRepo } - } else { + } else { // {:headOwner}/{:headRepoName}:{:headBranch} case, across forks ci.HeadRepo, err = repo_model.GetRepositoryByOwnerAndName(ctx, headInfosSplit[0], headInfosSplit[1]) if err != nil { if repo_model.IsErrRepoNotExist(err) { diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index f0304de9b75a3..08e0f285563cd 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -229,7 +229,7 @@ func TestCompareRawDiffPatch(t *testing.T) { respTs = respTs.In(time.Local) // Format the timestamp to match the expected format in the patch - customFormat := "Mon, 02 Jan 2006 15:04:05 -0700" + customFormat := "Mon, 2 Jan 2006 15:04:05 -0700" respTsStr := respTs.Format(customFormat) req := NewRequest(t, "GET", fmt.Sprintf("/user1/test_raw_diff/compare/%s...%s.patch", oldRef.ID.String(), newRef.ID.String()))