Skip to content

Commit 98175f1

Browse files
committed
Revert headcommitid change
1 parent cbce199 commit 98175f1

File tree

9 files changed

+33
-36
lines changed

9 files changed

+33
-36
lines changed

models/issues/pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ type PullRequest struct {
138138
BaseRepoID int64 `xorm:"INDEX"`
139139
BaseRepo *repo_model.Repository `xorm:"-"`
140140
HeadBranch string
141+
HeadCommitID string `xorm:"-"`
141142
BaseBranch string
142143
MergeBase string `xorm:"VARCHAR(64)"`
143144
AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"`

routers/web/repo/issue_comment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func NewComment(ctx *context.Context) {
9696

9797
// Regenerate patch and test conflict.
9898
if pr == nil {
99+
issue.PullRequest.HeadCommitID = ""
99100
pull_service.StartPullRequestCheckImmediately(ctx, issue.PullRequest)
100101
}
101102

routers/web/repo/pull_review.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,7 @@ func UpdateViewedFiles(ctx *context.Context) {
318318

319319
// Expect the review to have been now if no head commit was supplied
320320
if data.HeadCommitSHA == "" {
321-
data.HeadCommitSHA, err = ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitHeadRefName())
322-
if err != nil {
323-
log.Warn("Attempted to get ref commit id: %v", err)
324-
ctx.Resp.WriteHeader(http.StatusBadRequest)
325-
return
326-
}
321+
data.HeadCommitSHA = pull.HeadCommitID
327322
}
328323

329324
updatedFiles := make(map[string]pull_model.ViewedState, len(data.Files))

routers/web/repo/pull_review_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ func TestRenderConversation(t *testing.T) {
4141

4242
var preparedComment *issues_model.Comment
4343
run("prepare", func(t *testing.T, ctx *context.Context, resp *httptest.ResponseRecorder) {
44-
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitHeadRefName())
45-
assert.NoError(t, err)
46-
comment, err := pull.CreateCodeComment(ctx, pr.Issue.Poster, ctx.Repo.GitRepo, pr.Issue, 1, "content", "", false, 0, headCommitID, nil)
44+
comment, err := pull.CreateCodeComment(ctx, pr.Issue.Poster, ctx.Repo.GitRepo, pr.Issue, 1, "content", "", false, 0, pr.HeadCommitID, nil)
4745
require.NoError(t, err)
4846

4947
comment.Invalidated = true

services/agit/agit.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,21 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
142142
}
143143

144144
pr := &issues_model.PullRequest{
145-
HeadRepoID: repo.ID,
146-
BaseRepoID: repo.ID,
147-
HeadBranch: headBranch,
148-
BaseBranch: baseBranchName,
149-
HeadRepo: repo,
150-
BaseRepo: repo,
151-
MergeBase: "",
152-
Type: issues_model.PullRequestGitea,
153-
Flow: issues_model.PullRequestFlowAGit,
145+
HeadRepoID: repo.ID,
146+
BaseRepoID: repo.ID,
147+
HeadBranch: headBranch,
148+
HeadCommitID: opts.NewCommitIDs[i],
149+
BaseBranch: baseBranchName,
150+
HeadRepo: repo,
151+
BaseRepo: repo,
152+
MergeBase: "",
153+
Type: issues_model.PullRequestGitea,
154+
Flow: issues_model.PullRequestFlowAGit,
154155
}
155156
prOpts := &pull_service.NewPullRequestOptions{
156-
Repo: repo,
157-
Issue: prIssue,
158-
PullRequest: pr,
159-
HeadCommitID: opts.NewCommitIDs[i],
157+
Repo: repo,
158+
Issue: prIssue,
159+
PullRequest: pr,
160160
}
161161
if err := pull_service.NewPullRequest(ctx, prOpts); err != nil {
162162
return nil, err
@@ -214,7 +214,8 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
214214
}
215215
}
216216

217-
if err = pull_service.UpdatePullRequestAgitFlowHead(ctx, pr, opts.NewCommitIDs[i]); err != nil {
217+
pr.HeadCommitID = opts.NewCommitIDs[i]
218+
if err = pull_service.UpdatePullRequestAgitFlowHead(ctx, pr, pr.HeadCommitID); err != nil {
218219
return nil, fmt.Errorf("failed to update pull ref. Error: %w", err)
219220
}
220221

services/pull/patch.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ func testPullRequestTmpRepoBranchMergeable(ctx context.Context, prCtx *prTmpRepo
100100
}
101101
}
102102
pr.MergeBase = strings.TrimSpace(pr.MergeBase)
103-
headCommitID, err := gitRepo.GetRefCommitID(git.BranchPrefix + "tracking")
104-
if err != nil {
103+
if pr.HeadCommitID, err = gitRepo.GetRefCommitID(git.BranchPrefix + "tracking"); err != nil {
105104
return fmt.Errorf("GetBranchCommitID: can't find commit ID for head: %w", err)
106105
}
107106

108-
if headCommitID == pr.MergeBase {
107+
if pr.HeadCommitID == pr.MergeBase {
109108
pr.Status = issues_model.PullRequestStatusAncestor
110109
return nil
111110
}

services/pull/pull.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func getPullWorkingLockKey(prID int64) string {
4343
type NewPullRequestOptions struct {
4444
Repo *repo_model.Repository
4545
Issue *issues_model.Issue
46-
HeadCommitID string
4746
LabelIDs []int64
4847
AttachmentUUIDs []string
4948
PullRequest *issues_model.PullRequest
@@ -54,7 +53,7 @@ type NewPullRequestOptions struct {
5453

5554
// NewPullRequest creates new pull request with labels for repository.
5655
func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
57-
if opts.PullRequest.Flow == issues_model.PullRequestFlowAGit && opts.HeadCommitID == "" {
56+
if opts.PullRequest.Flow == issues_model.PullRequestFlowAGit && opts.PullRequest.HeadCommitID == "" {
5857
return errors.New("head commit ID cannot be empty for agit flow")
5958
}
6059

@@ -131,7 +130,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
131130

132131
// update head commit id into git repository
133132
if pr.Flow == issues_model.PullRequestFlowAGit {
134-
err = UpdatePullRequestAgitFlowHead(ctx, pr, opts.HeadCommitID)
133+
err = UpdatePullRequestAgitFlowHead(ctx, pr, pr.HeadCommitID)
135134
} else {
136135
err = UpdatePullRequestGithubFlowHead(ctx, pr)
137136
}
@@ -771,12 +770,12 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ
771770
if pr.Flow == issues_model.PullRequestFlowGithub {
772771
headCommit, err = gitRepo.GetBranchCommit(pr.HeadBranch)
773772
} else {
774-
headCommitID, err1 := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
775-
if err1 != nil {
776-
log.Error("Unable to get head commit: %s Error: %v", pr.GetGitHeadRefName(), err1)
773+
pr.HeadCommitID, err = gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
774+
if err != nil {
775+
log.Error("Unable to get head commit: %s Error: %v", pr.GetGitHeadRefName(), err)
777776
return ""
778777
}
779-
headCommit, err = gitRepo.GetCommit(headCommitID)
778+
headCommit, err = gitRepo.GetCommit(pr.HeadCommitID)
780779
}
781780
if err != nil {
782781
log.Error("Unable to get head commit: %s Error: %v", pr.HeadBranch, err)
@@ -998,11 +997,11 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
998997
return false, err
999998
}
1000999
} else {
1001-
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
1000+
pr.HeadCommitID, err = baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
10021001
if err != nil {
10031002
return false, err
10041003
}
1005-
if headCommit, err = baseGitRepo.GetCommit(headCommitID); err != nil {
1004+
if headCommit, err = baseGitRepo.GetCommit(pr.HeadCommitID); err != nil {
10061005
return false, err
10071006
}
10081007
}

services/pull/temp_repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,13 @@ func createTemporaryRepoForPR(ctx context.Context, pr *issues_model.PullRequest)
166166
}
167167

168168
trackingBranch := "tracking"
169+
objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName)
169170
// Fetch head branch
170171
var headBranch string
171172
if pr.Flow == issues_model.PullRequestFlowGithub {
172173
headBranch = git.BranchPrefix + pr.HeadBranch
174+
} else if len(pr.HeadCommitID) == objectFormat.FullLength() { // for not created pull request
175+
headBranch = pr.HeadCommitID
173176
} else {
174177
headBranch = pr.GetGitHeadRefName()
175178
}

tests/integration/git_misc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestAgitReviewStaleness(t *testing.T) {
170170
assert.NoError(t, pr.LoadIssue(t.Context()))
171171

172172
// Get initial commit ID for the review
173-
initialCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
173+
initialCommitID := pr.HeadCommitID
174174
assert.NoError(t, err)
175175
t.Logf("Initial commit ID: %s", initialCommitID)
176176

0 commit comments

Comments
 (0)