From 33e8926efe49514132c5c8336635b0a1c94ec250 Mon Sep 17 00:00:00 2001 From: Mai-Lapyst Date: Fri, 5 Apr 2024 05:27:20 +0200 Subject: [PATCH 1/3] Fix view file button in diff compare --- routers/web/repo/compare.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index cfb0e859bd..93c224b7be 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -684,7 +684,7 @@ func PrepareCompareDiff( ctx.Data["Username"] = ci.HeadUser.Name ctx.Data["Reponame"] = ci.HeadRepo.Name - setCompareContext(ctx, beforeCommit, headCommit, ci.HeadUser.Name, repo.Name) + setCompareContext(ctx, beforeCommit, headCommit, ci.HeadUser.Name, ci.HeadRepo.Name) return false } From 06478da63ba1d7ee3f325344d7de02f93a5066c8 Mon Sep 17 00:00:00 2001 From: Mai-Lapyst Date: Fri, 5 Apr 2024 08:19:08 +0200 Subject: [PATCH 2/3] Add integration test --- tests/integration/compare_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 5d5529c36e..c6454c51ce 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" + "code.gitea.io/gitea/modules/gitrepo" repo_service "code.gitea.io/gitea/services/repository" "code.gitea.io/gitea/tests" @@ -182,3 +183,32 @@ func TestCompareWithPRsDisabled(t *testing.T) { }) }) } + +func TestCompareCrossRepo(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + session := loginUser(t, "user1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1-copy") + testCreateBranch(t, session, "user1", "repo1-copy", "branch/master", "recent-push", http.StatusSeeOther) + testEditFile(t, session, "user1", "repo1-copy", "recent-push", "README.md", "Hello recently!\n") + + repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user1", "repo1-copy") + assert.NoError(t, err) + + gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, repo) + assert.NoError(t, err) + + lastCommit, err := gitRepo.GetBranchCommitID("recent-push") + assert.NoError(t, err) + assert.NotEmpty(t, lastCommit) + + t.Run("view file button links to correct file in fork", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", "/user2/repo1/compare/master...user1/repo1-copy:recent-push") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + htmlDoc.AssertElement(t, "a[href='/user1/repo1-copy/src/commit/"+lastCommit+"/README.md']", true) + htmlDoc.AssertElement(t, "a[href='/user1/repo1/src/commit/"+lastCommit+"/README.md']", false) + }) + }) +} From ca8479c681b2f1f284b747d4170728ec281c6786 Mon Sep 17 00:00:00 2001 From: Mai-Lapyst Date: Sat, 6 Apr 2024 11:19:32 +0200 Subject: [PATCH 3/3] Update integration test --- tests/integration/compare_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index c6454c51ce..0929e8938e 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/gitrepo" repo_service "code.gitea.io/gitea/services/repository" "code.gitea.io/gitea/tests" @@ -191,11 +192,11 @@ func TestCompareCrossRepo(t *testing.T) { testCreateBranch(t, session, "user1", "repo1-copy", "branch/master", "recent-push", http.StatusSeeOther) testEditFile(t, session, "user1", "repo1-copy", "recent-push", "README.md", "Hello recently!\n") - repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user1", "repo1-copy") - assert.NoError(t, err) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1-copy"}) gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, repo) assert.NoError(t, err) + defer gitRepo.Close() lastCommit, err := gitRepo.GetBranchCommitID("recent-push") assert.NoError(t, err)