mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-23 08:35:34 +02:00
fix bug
This commit is contained in:
parent
c566b49e02
commit
dcffdb1a42
@ -592,7 +592,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git_s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if compareInfo.HeadCommitID == compareInfo.MergeBase {
|
if compareInfo.HeadCommitID == compareInfo.MergeBase {
|
||||||
ctx.Data["IsNothingToCompare"] = true
|
ctx.Data["DiffNotAvailable"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if pull.IsWorkInProgress(ctx) {
|
if pull.IsWorkInProgress(ctx) {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<div class="commits-table-left tw-flex tw-items-center">
|
<div class="commits-table-left tw-flex tw-items-center">
|
||||||
{{if or .PageIsCommits (gt .CommitCount 0)}}
|
{{if or .PageIsCommits (gt .CommitCount 0)}}
|
||||||
{{.CommitCount}} {{ctx.Locale.Tr "repo.commits.commits"}}
|
{{.CommitCount}} {{ctx.Locale.Tr "repo.commits.commits"}}
|
||||||
{{else if .IsNothingToCompare}}
|
{{else if .DiffNotAvailable}}
|
||||||
{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}
|
{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{ctx.Locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}}
|
{{ctx.Locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}}
|
||||||
|
|||||||
@ -7,16 +7,22 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||||
"code.gitea.io/gitea/modules/test"
|
"code.gitea.io/gitea/modules/test"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPullCompare(t *testing.T) {
|
func TestPullCompare(t *testing.T) {
|
||||||
@ -170,3 +176,68 @@ func TestPullCompare_EnableAllowEditsFromMaintainer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPullCompareForcePushDroppedCommit(t *testing.T) {
|
||||||
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||||
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
|
repo, err := repo_service.CreateRepositoryDirectly(t.Context(), user, user, repo_service.CreateRepoOptions{
|
||||||
|
Name: "compare-force-push",
|
||||||
|
AutoInit: true,
|
||||||
|
DefaultBranch: "master",
|
||||||
|
Readme: "Default",
|
||||||
|
}, true)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
session := loginUser(t, user.Name)
|
||||||
|
u.Path = fmt.Sprintf("/%s/%s.git", user.Name, repo.Name)
|
||||||
|
u.User = url.UserPassword(user.Name, userPassword)
|
||||||
|
|
||||||
|
dstPath := t.TempDir()
|
||||||
|
doGitClone(dstPath, u)(t)
|
||||||
|
doGitCreateBranch(dstPath, "feature/drop-commit")(t)
|
||||||
|
|
||||||
|
doGitCheckoutWriteFileCommit(localGitAddCommitOptions{
|
||||||
|
LocalRepoPath: dstPath,
|
||||||
|
CheckoutBranch: "feature/drop-commit",
|
||||||
|
TreeFilePath: "README.md",
|
||||||
|
TreeFileContent: "first\n",
|
||||||
|
})(t)
|
||||||
|
doGitCheckoutWriteFileCommit(localGitAddCommitOptions{
|
||||||
|
LocalRepoPath: dstPath,
|
||||||
|
CheckoutBranch: "feature/drop-commit",
|
||||||
|
TreeFilePath: "README.md",
|
||||||
|
TreeFileContent: "first\nsecond\n",
|
||||||
|
})(t)
|
||||||
|
doGitPushTestRepository(dstPath, "origin", "feature/drop-commit")(t)
|
||||||
|
|
||||||
|
resp := testPullCreate(t, session, user.Name, repo.Name, true, "master", "feature/drop-commit", "Force push compare")
|
||||||
|
prURL := test.RedirectURL(resp)
|
||||||
|
issueIndex, err := strconv.ParseInt(path.Base(prURL), 10, 64)
|
||||||
|
require.NoError(t, err)
|
||||||
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID, Index: issueIndex})
|
||||||
|
require.NoError(t, issue.LoadPullRequest(t.Context()))
|
||||||
|
|
||||||
|
err = gitcmd.NewCommand("reset", "--hard", "HEAD~1").WithDir(dstPath).Run(t.Context())
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = gitcmd.NewCommand("push", "--force", "origin", "feature/drop-commit").WithDir(dstPath).Run(t.Context())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var compareURL string
|
||||||
|
require.Eventually(t, func() bool {
|
||||||
|
req := NewRequest(t, "GET", prURL)
|
||||||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
selection := htmlDoc.doc.Find("a.comment-text-label[href*='/compare/']")
|
||||||
|
if selection.Length() == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
compareURL = selection.Last().AttrOr("href", "")
|
||||||
|
return compareURL != ""
|
||||||
|
}, 5*time.Second, 20*time.Millisecond)
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", compareURL)
|
||||||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
assert.Positive(t, htmlDoc.doc.Find("#diff-file-boxes [data-new-filename=\"README.md\"]").Length())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user