Skip to content

Commit e3ade4e

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Retarget depending pulls when the parent branch is deleted (go-gitea#28686) Bump `@github/relative-time-element` to 4.3.1 (go-gitea#28819) Fix reverting a merge commit failing (go-gitea#28794) Render code block in activity tab (go-gitea#28816) Remove trust model selection from repository creation on web page because it can be changed in settings later (go-gitea#28814)
2 parents b112684 + 49eb168 commit e3ade4e

33 files changed

+270
-79
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,9 @@ LEVEL = Info
10671067
;;
10681068
;; In addition to testing patches using the three-way merge method, re-test conflicting patches with git apply
10691069
;TEST_CONFLICTING_PATCHES_WITH_GIT_APPLY = false
1070+
;;
1071+
;; Retarget child pull requests to the parent pull request branch target on merge of parent pull request. It only works on merged PRs where the head and base branch target the same repo.
1072+
;RETARGET_CHILDREN_ON_MERGE = true
10701073

10711074
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10721075
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ In addition, there is _`StaticRootPath`_ which can be set as a built-in at build
135135
- `POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES`: **false**: In default squash-merge messages include the commit message of all commits comprising the pull request.
136136
- `ADD_CO_COMMITTER_TRAILERS`: **true**: Add co-authored-by and co-committed-by trailers to merge commit messages if committer does not match author.
137137
- `TEST_CONFLICTING_PATCHES_WITH_GIT_APPLY`: **false**: PR patches are tested using a three-way merge method to discover if there are conflicts. If this setting is set to **true**, conflicting patches will be retested using `git apply` - This was the previous behaviour in 1.18 (and earlier) but is somewhat inefficient. Please report if you find that this setting is required.
138+
- `RETARGET_CHILDREN_ON_MERGE`: **true**: Retarget child pull requests to the parent pull request branch target on merge of parent pull request. It only works on merged PRs where the head and base branch target the same repo.
138139

139140
### Repository - Issue (`repository.issue`)
140141

models/fixtures/repo_unit.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,3 +669,10 @@
669669
type: 10
670670
config: "{}"
671671
created_unix: 946684810
672+
673+
-
674+
id: 101
675+
repo_id: 59
676+
type: 1
677+
config: "{}"
678+
created_unix: 946684810

models/fixtures/repository.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,3 +1693,16 @@
16931693
size: 0
16941694
is_fsck_enabled: true
16951695
close_issues_via_commit_in_any_branch: false
1696+
1697+
-
1698+
id: 59
1699+
owner_id: 2
1700+
owner_name: user2
1701+
lower_name: test_commit_revert
1702+
name: test_commit_revert
1703+
default_branch: main
1704+
is_empty: false
1705+
is_archived: false
1706+
is_private: true
1707+
status: 0
1708+
num_issues: 0

models/fixtures/user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
num_followers: 2
6767
num_following: 1
6868
num_stars: 2
69-
num_repos: 14
69+
num_repos: 15
7070
num_teams: 0
7171
num_members: 0
7272
visibility: 0

modules/setting/repository.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ var (
8585
PopulateSquashCommentWithCommitMessages bool
8686
AddCoCommitterTrailers bool
8787
TestConflictingPatchesWithGitApply bool
88+
RetargetChildrenOnMerge bool
8889
} `ini:"repository.pull-request"`
8990

9091
// Issue Setting
@@ -209,6 +210,7 @@ var (
209210
PopulateSquashCommentWithCommitMessages bool
210211
AddCoCommitterTrailers bool
211212
TestConflictingPatchesWithGitApply bool
213+
RetargetChildrenOnMerge bool
212214
}{
213215
WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
214216
// Same as GitHub. See
@@ -223,6 +225,7 @@ var (
223225
DefaultMergeMessageOfficialApproversOnly: true,
224226
PopulateSquashCommentWithCommitMessages: false,
225227
AddCoCommitterTrailers: true,
228+
RetargetChildrenOnMerge: true,
226229
},
227230

228231
// Issue settings

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@citation-js/plugin-software-formats": "0.6.1",
1111
"@claviska/jquery-minicolors": "2.3.6",
1212
"@github/markdown-toolbar-element": "2.2.1",
13-
"@github/relative-time-element": "4.3.0",
13+
"@github/relative-time-element": "4.3.1",
1414
"@github/text-expander-element": "2.6.1",
1515
"@mcaptcha/vanilla-glue": "0.1.0-alpha-3",
1616
"@primer/octicons": "19.8.0",

routers/api/v1/repo/pull.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,10 @@ func MergePullRequest(ctx *context.APIContext) {
913913
}
914914
defer headRepo.Close()
915915
}
916+
if err := pull_service.RetargetChildrenOnMerge(ctx, ctx.Doer, pr); err != nil {
917+
ctx.Error(http.StatusInternalServerError, "RetargetChildrenOnMerge", err)
918+
return
919+
}
916920
if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, headRepo, pr.HeadBranch); err != nil {
917921
switch {
918922
case git.IsErrBranchNotExist(err):

routers/web/repo/pull.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,12 @@ func CleanUpPullRequest(ctx *context.Context) {
15871587

15881588
func deleteBranch(ctx *context.Context, pr *issues_model.PullRequest, gitRepo *git.Repository) {
15891589
fullBranchName := pr.HeadRepo.FullName() + ":" + pr.HeadBranch
1590+
1591+
if err := pull_service.RetargetChildrenOnMerge(ctx, ctx.Doer, pr); err != nil {
1592+
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
1593+
return
1594+
}
1595+
15901596
if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, gitRepo, pr.HeadBranch); err != nil {
15911597
switch {
15921598
case git.IsErrBranchNotExist(err):

routers/web/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func CreatePost(ctx *context.Context) {
288288
DefaultBranch: form.DefaultBranch,
289289
AutoInit: form.AutoInit,
290290
IsTemplate: form.Template,
291-
TrustModel: repo_model.ToTrustModel(form.TrustModel),
291+
TrustModel: repo_model.DefaultTrustModel,
292292
ObjectFormatName: form.ObjectFormatName,
293293
})
294294
if err == nil {

services/forms/repo_form.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ import (
2121
"gitea.com/go-chi/binding"
2222
)
2323

24-
// _______________________________________ _________.______________________ _______________.___.
25-
// \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
26-
// | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
27-
// | | \| \ | | / | \/ \| | | | / | \ | \\____ |
28-
// |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
29-
// \/ \/ \/ \/ \/ \/ \/
30-
3124
// CreateRepoForm form for creating repository
3225
type CreateRepoForm struct {
3326
UID int64 `binding:"Required"`
@@ -50,7 +43,6 @@ type CreateRepoForm struct {
5043
Avatar bool
5144
Labels bool
5245
ProtectedBranch bool
53-
TrustModel string
5446

5547
ForkSingleBranch string
5648
ObjectFormatName string

services/packages/cargo/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func alterRepositoryContent(ctx context.Context, doer *user_model.User, repo *re
267267
defer t.Close()
268268

269269
var lastCommitID string
270-
if err := t.Clone(repo.DefaultBranch); err != nil {
270+
if err := t.Clone(repo.DefaultBranch, true); err != nil {
271271
if !git.IsErrBranchNotExist(err) || !repo.IsEmpty {
272272
return err
273273
}

services/pull/pull.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,43 @@ func (errs errlist) Error() string {
546546
return ""
547547
}
548548

549+
// RetargetChildrenOnMerge retarget children pull requests on merge if possible
550+
func RetargetChildrenOnMerge(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) error {
551+
if setting.Repository.PullRequest.RetargetChildrenOnMerge && pr.BaseRepoID == pr.HeadRepoID {
552+
return RetargetBranchPulls(ctx, doer, pr.HeadRepoID, pr.HeadBranch, pr.BaseBranch)
553+
}
554+
return nil
555+
}
556+
557+
// RetargetBranchPulls change target branch for all pull requests whose base branch is the branch
558+
// Both branch and targetBranch must be in the same repo (for security reasons)
559+
func RetargetBranchPulls(ctx context.Context, doer *user_model.User, repoID int64, branch, targetBranch string) error {
560+
prs, err := issues_model.GetUnmergedPullRequestsByBaseInfo(ctx, repoID, branch)
561+
if err != nil {
562+
return err
563+
}
564+
565+
if err := issues_model.PullRequestList(prs).LoadAttributes(ctx); err != nil {
566+
return err
567+
}
568+
569+
var errs errlist
570+
for _, pr := range prs {
571+
if err = pr.Issue.LoadRepo(ctx); err != nil {
572+
errs = append(errs, err)
573+
} else if err = ChangeTargetBranch(ctx, pr, doer, targetBranch); err != nil &&
574+
!issues_model.IsErrIssueIsClosed(err) && !models.IsErrPullRequestHasMerged(err) &&
575+
!issues_model.IsErrPullRequestAlreadyExists(err) {
576+
errs = append(errs, err)
577+
}
578+
}
579+
580+
if len(errs) > 0 {
581+
return errs
582+
}
583+
return nil
584+
}
585+
549586
// CloseBranchPulls close all the pull requests who's head branch is the branch
550587
func CloseBranchPulls(ctx context.Context, doer *user_model.User, repoID int64, branch string) error {
551588
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(ctx, repoID, branch)

services/repository/files/cherry_pick.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod
3131
log.Error("%v", err)
3232
}
3333
defer t.Close()
34-
if err := t.Clone(opts.OldBranch); err != nil {
34+
if err := t.Clone(opts.OldBranch, false); err != nil {
3535
return nil, err
3636
}
3737
if err := t.SetDefaultIndex(); err != nil {
3838
return nil, err
3939
}
40+
if err := t.RefreshIndex(); err != nil {
41+
return nil, err
42+
}
4043

4144
// Get the commit of the original branch
4245
commit, err := t.GetBranchCommit(opts.OldBranch)

services/repository/files/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func GetDiffPreview(ctx context.Context, repo *repo_model.Repository, branch, tr
2121
return nil, err
2222
}
2323
defer t.Close()
24-
if err := t.Clone(branch); err != nil {
24+
if err := t.Clone(branch, true); err != nil {
2525
return nil, err
2626
}
2727
if err := t.SetDefaultIndex(); err != nil {

services/repository/files/patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user
113113
log.Error("%v", err)
114114
}
115115
defer t.Close()
116-
if err := t.Clone(opts.OldBranch); err != nil {
116+
if err := t.Clone(opts.OldBranch, true); err != nil {
117117
return nil, err
118118
}
119119
if err := t.SetDefaultIndex(); err != nil {

services/repository/files/temp_repo.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ func (t *TemporaryUploadRepository) Close() {
5151
}
5252

5353
// Clone the base repository to our path and set branch as the HEAD
54-
func (t *TemporaryUploadRepository) Clone(branch string) error {
55-
if _, _, err := git.NewCommand(t.ctx, "clone", "-s", "--bare", "-b").AddDynamicArguments(branch, t.repo.RepoPath(), t.basePath).RunStdString(nil); err != nil {
54+
func (t *TemporaryUploadRepository) Clone(branch string, bare bool) error {
55+
cmd := git.NewCommand(t.ctx, "clone", "-s", "-b").AddDynamicArguments(branch, t.repo.RepoPath(), t.basePath)
56+
if bare {
57+
cmd.AddArguments("--bare")
58+
}
59+
60+
if _, _, err := cmd.RunStdString(nil); err != nil {
5661
stderr := err.Error()
5762
if matched, _ := regexp.MatchString(".*Remote branch .* not found in upstream origin.*", stderr); matched {
5863
return git.ErrBranchNotExist{
@@ -97,6 +102,14 @@ func (t *TemporaryUploadRepository) SetDefaultIndex() error {
97102
return nil
98103
}
99104

105+
// RefreshIndex looks at the current index and checks to see if merges or updates are needed by checking stat() information.
106+
func (t *TemporaryUploadRepository) RefreshIndex() error {
107+
if _, _, err := git.NewCommand(t.ctx, "update-index", "--refresh").RunStdString(&git.RunOpts{Dir: t.basePath}); err != nil {
108+
return fmt.Errorf("RefreshIndex: %w", err)
109+
}
110+
return nil
111+
}
112+
100113
// LsFiles checks if the given filename arguments are in the index
101114
func (t *TemporaryUploadRepository) LsFiles(filenames ...string) ([]string, error) {
102115
stdOut := new(bytes.Buffer)

services/repository/files/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
146146
}
147147
defer t.Close()
148148
hasOldBranch := true
149-
if err := t.Clone(opts.OldBranch); err != nil {
149+
if err := t.Clone(opts.OldBranch, true); err != nil {
150150
for _, file := range opts.Files {
151151
if file.Operation == "delete" {
152152
return nil, err

services/repository/files/upload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
8787
defer t.Close()
8888

8989
hasOldBranch := true
90-
if err = t.Clone(opts.OldBranch); err != nil {
90+
if err = t.Clone(opts.OldBranch, true); err != nil {
9191
if !git.IsErrBranchNotExist(err) || !repo.IsEmpty {
9292
return err
9393
}

templates/repo/activity.tmpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<span class="ui green label">{{ctx.Locale.Tr "repo.activity.published_release_label"}}</span>
127127
{{.TagName}}
128128
{{if not .IsTag}}
129-
<a class="title" href="{{$.RepoLink}}/src/{{.TagName | PathEscapeSegments}}">{{.Title | RenderEmoji $.Context}}</a>
129+
<a class="title" href="{{$.RepoLink}}/src/{{.TagName | PathEscapeSegments}}">{{.Title | RenderEmoji $.Context | RenderCodeBlock}}</a>
130130
{{end}}
131131
{{TimeSinceUnix .CreatedUnix ctx.Locale}}
132132
</p>
@@ -146,7 +146,7 @@
146146
{{range .Activity.MergedPRs}}
147147
<p class="desc">
148148
<span class="ui purple label">{{ctx.Locale.Tr "repo.activity.merged_prs_label"}}</span>
149-
#{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Issue.Title | RenderEmoji $.Context}}</a>
149+
#{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Issue.Title | RenderEmoji $.Context | RenderCodeBlock}}</a>
150150
{{TimeSinceUnix .MergedUnix ctx.Locale}}
151151
</p>
152152
{{end}}
@@ -165,7 +165,7 @@
165165
{{range .Activity.OpenedPRs}}
166166
<p class="desc">
167167
<span class="ui green label">{{ctx.Locale.Tr "repo.activity.opened_prs_label"}}</span>
168-
#{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Issue.Title | RenderEmoji $.Context}}</a>
168+
#{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Issue.Title | RenderEmoji $.Context | RenderCodeBlock}}</a>
169169
{{TimeSinceUnix .Issue.CreatedUnix ctx.Locale}}
170170
</p>
171171
{{end}}
@@ -184,7 +184,7 @@
184184
{{range .Activity.ClosedIssues}}
185185
<p class="desc">
186186
<span class="ui red label">{{ctx.Locale.Tr "repo.activity.closed_issue_label"}}</span>
187-
#{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji $.Context}}</a>
187+
#{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji $.Context | RenderCodeBlock}}</a>
188188
{{TimeSinceUnix .ClosedUnix ctx.Locale}}
189189
</p>
190190
{{end}}
@@ -203,7 +203,7 @@
203203
{{range .Activity.OpenedIssues}}
204204
<p class="desc">
205205
<span class="ui green label">{{ctx.Locale.Tr "repo.activity.new_issue_label"}}</span>
206-
#{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji $.Context}}</a>
206+
#{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji $.Context | RenderCodeBlock}}</a>
207207
{{TimeSinceUnix .CreatedUnix ctx.Locale}}
208208
</p>
209209
{{end}}
@@ -221,9 +221,9 @@
221221
<span class="ui green label">{{ctx.Locale.Tr "repo.activity.unresolved_conv_label"}}</span>
222222
#{{.Index}}
223223
{{if .IsPull}}
224-
<a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Title | RenderEmoji $.Context}}</a>
224+
<a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Title | RenderEmoji $.Context | RenderCodeBlock}}</a>
225225
{{else}}
226-
<a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji $.Context}}</a>
226+
<a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji $.Context | RenderCodeBlock}}</a>
227227
{{end}}
228228
{{TimeSinceUnix .UpdatedUnix ctx.Locale}}
229229
</p>

0 commit comments

Comments
 (0)