Skip to content

Commit 04a5bb6

Browse files
authored
Merge branch 'master' into only-close-the-gitrepo-at-the-end-of-wrap
2 parents 73b34f8 + f5eb33c commit 04a5bb6

File tree

21 files changed

+100
-42
lines changed

21 files changed

+100
-42
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ RUN addgroup \
5353
-u 1000 \
5454
-G git \
5555
git && \
56-
echo "git:$(dd if=/dev/urandom bs=24 count=1 status=none | base64)" | chpasswd
56+
echo "git:*" | chpasswd -e
5757

5858
ENV USER git
5959
ENV GITEA_CUSTOM /data/gitea

Dockerfile.rootless

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ RUN addgroup \
4646
-s /bin/bash \
4747
-u 1000 \
4848
-G git \
49-
git && \
50-
echo "git:$(dd if=/dev/urandom bs=24 count=1 status=none | base64)" | chpasswd
49+
git
5150

5251
RUN mkdir -p /var/lib/gitea /etc/gitea
5352
RUN chown git:git /var/lib/gitea /etc/gitea

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
5959
- `MIRROR_QUEUE_LENGTH`: **1000**: Patch test queue length, increase if pull request patch
6060
testing starts hanging.
6161
- `PREFERRED_LICENSES`: **Apache License 2.0,MIT License**: Preferred Licenses to place at
62-
the top of the list. Name must match file name in conf/license or custom/conf/license.
62+
the top of the list. Name must match file name in options/license or custom/options/license.
6363
- `DISABLE_HTTP_GIT`: **false**: Disable the ability to interact with repositories over the
6464
HTTP protocol.
6565
- `USE_COMPAT_SSH_URI`: **false**: Force ssh:// clone url instead of scp-style uri when

docs/content/doc/advanced/external-renderers.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ IS_INPUT_FILE = true
7070
[markup.restructuredtext]
7171
ENABLED = true
7272
FILE_EXTENSIONS = .rst
73-
RENDER_COMMAND = rst2html.py
73+
RENDER_COMMAND = "timeout 30s pandoc +RTS -M512M -RTS -f rst"
7474
IS_INPUT_FILE = false
7575
```
7676

models/consistency.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,15 @@ func CountOrphanedObjects(subject, refobject, joinCond string) (int64, error) {
296296

297297
// DeleteOrphanedObjects delete subjects with have no existing refobject anymore
298298
func DeleteOrphanedObjects(subject, refobject, joinCond string) error {
299-
_, err := x.In("id", builder.Select("`"+subject+"`.id").
299+
subQuery := builder.Select("`"+subject+"`.id").
300300
From("`"+subject+"`").
301301
Join("LEFT", "`"+refobject+"`", joinCond).
302-
Where(builder.IsNull{"`" + refobject + "`.id"})).
303-
Delete("`" + subject + "`")
302+
Where(builder.IsNull{"`" + refobject + "`.id"})
303+
sql, args, err := builder.Delete(builder.In("id", subQuery)).From("`" + subject + "`").ToSQL()
304+
if err != nil {
305+
return err
306+
}
307+
_, err = x.Exec(append([]interface{}{sql}, args...)...)
304308
return err
305309
}
306310

models/consistency_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2021 Gitea. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package models
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestDeleteOrphanedObjects(t *testing.T) {
14+
assert.NoError(t, PrepareTestDatabase())
15+
16+
countBefore, err := x.Count(&PullRequest{})
17+
assert.NoError(t, err)
18+
19+
_, err = x.Insert(&PullRequest{IssueID: 1000}, &PullRequest{IssueID: 1001}, &PullRequest{IssueID: 1003})
20+
assert.NoError(t, err)
21+
22+
orphaned, err := CountOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id")
23+
assert.NoError(t, err)
24+
assert.EqualValues(t, 3, orphaned)
25+
26+
err = DeleteOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id")
27+
assert.NoError(t, err)
28+
29+
countAfter, err := x.Count(&PullRequest{})
30+
assert.NoError(t, err)
31+
assert.EqualValues(t, countBefore, countAfter)
32+
}

models/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
14721472
&LanguageStat{RepoID: repoID},
14731473
&Comment{RefRepoID: repoID},
14741474
&Task{RepoID: repoID},
1475+
&ProtectedBranch{RepoID: repoID},
14751476
); err != nil {
14761477
return fmt.Errorf("deleteBeans: %v", err)
14771478
}

models/user.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (u *User) CanImportLocal() bool {
301301
// DashboardLink returns the user dashboard page link.
302302
func (u *User) DashboardLink() string {
303303
if u.IsOrganization() {
304-
return setting.AppSubURL + "/org/" + u.Name + "/dashboard/"
304+
return u.OrganisationLink() + "/dashboard/"
305305
}
306306
return setting.AppSubURL + "/"
307307
}
@@ -316,6 +316,11 @@ func (u *User) HTMLURL() string {
316316
return setting.AppURL + u.Name
317317
}
318318

319+
// OrganisationLink returns the organization sub page link.
320+
func (u *User) OrganisationLink() string {
321+
return setting.AppSubURL + "/org/" + u.Name
322+
}
323+
319324
// GenerateEmailActivateCode generates an activate code based on user information and given e-mail.
320325
func (u *User) GenerateEmailActivateCode(email string) string {
321326
code := base.CreateTimeLimitCode(

modules/context/org.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
"code.gitea.io/gitea/models"
12-
"code.gitea.io/gitea/modules/setting"
1312
)
1413

1514
// Organization contains organization context
@@ -70,7 +69,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
7069

7170
// Force redirection when username is actually a user.
7271
if !org.IsOrganization() {
73-
ctx.Redirect(setting.AppSubURL + "/" + org.Name)
72+
ctx.Redirect(org.HomeLink())
7473
return
7574
}
7675

@@ -118,7 +117,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
118117
ctx.Data["IsOrganizationMember"] = ctx.Org.IsMember
119118
ctx.Data["CanCreateOrgRepo"] = ctx.Org.CanCreateOrgRepo
120119

121-
ctx.Org.OrgLink = setting.AppSubURL + "/org/" + org.Name
120+
ctx.Org.OrgLink = org.OrganisationLink()
122121
ctx.Data["OrgLink"] = ctx.Org.OrgLink
123122

124123
// Team.

modules/doctor/dbconsistency.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
2929
if count > 0 {
3030
if autofix {
3131
if err = models.DeleteOrphanedLabels(); err != nil {
32-
logger.Critical("Error: %v whilst deleting orphaned labels")
32+
logger.Critical("Error: %v whilst deleting orphaned labels", err)
3333
return err
3434
}
3535
logger.Info("%d labels without existing repository/organisation deleted", count)
@@ -47,7 +47,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
4747
if count > 0 {
4848
if autofix {
4949
if err = models.DeleteOrphanedIssueLabels(); err != nil {
50-
logger.Critical("Error: %v whilst deleting orphaned issue_labels")
50+
logger.Critical("Error: %v whilst deleting orphaned issue_labels", err)
5151
return err
5252
}
5353
logger.Info("%d issue_labels without existing label deleted", count)
@@ -65,7 +65,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
6565
if count > 0 {
6666
if autofix {
6767
if err = models.DeleteOrphanedIssues(); err != nil {
68-
logger.Critical("Error: %v whilst deleting orphaned issues")
68+
logger.Critical("Error: %v whilst deleting orphaned issues", err)
6969
return err
7070
}
7171
logger.Info("%d issues without existing repository deleted", count)
@@ -83,7 +83,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
8383
if count > 0 {
8484
if autofix {
8585
if err = models.DeleteOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id"); err != nil {
86-
logger.Critical("Error: %v whilst deleting orphaned objects")
86+
logger.Critical("Error: %v whilst deleting orphaned objects", err)
8787
return err
8888
}
8989
logger.Info("%d pull requests without existing issue deleted", count)
@@ -101,7 +101,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
101101
if count > 0 {
102102
if autofix {
103103
if err = models.DeleteOrphanedObjects("tracked_time", "issue", "tracked_time.issue_id=issue.id"); err != nil {
104-
logger.Critical("Error: %v whilst deleting orphaned objects")
104+
logger.Critical("Error: %v whilst deleting orphaned objects", err)
105105
return err
106106
}
107107
logger.Info("%d tracked times without existing issue deleted", count)
@@ -120,7 +120,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
120120
if autofix {
121121
updatedCount, err := models.FixNullArchivedRepository()
122122
if err != nil {
123-
logger.Critical("Error: %v whilst fixing null archived repositories")
123+
logger.Critical("Error: %v whilst fixing null archived repositories", err)
124124
return err
125125
}
126126
logger.Info("%d repositories with null is_archived updated", updatedCount)
@@ -139,7 +139,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
139139
if autofix {
140140
updatedCount, err := models.FixCommentTypeLabelWithEmptyLabel()
141141
if err != nil {
142-
logger.Critical("Error: %v whilst removing label comments with empty labels")
142+
logger.Critical("Error: %v whilst removing label comments with empty labels", err)
143143
return err
144144
}
145145
logger.Info("%d label comments with empty labels removed", updatedCount)
@@ -197,7 +197,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
197197
if autofix {
198198
err := models.FixBadSequences()
199199
if err != nil {
200-
logger.Critical("Error: %v whilst attempting to fix sequences")
200+
logger.Critical("Error: %v whilst attempting to fix sequences", err)
201201
return err
202202
}
203203
logger.Info("%d sequences updated", count)
@@ -207,6 +207,24 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
207207
}
208208
}
209209

210+
// find protected branches without existing repository
211+
count, err = models.CountOrphanedObjects("protected_branch", "repository", "protected_branch.repo_id=repository.id")
212+
if err != nil {
213+
logger.Critical("Error: %v whilst counting orphaned objects")
214+
return err
215+
}
216+
if count > 0 {
217+
if autofix {
218+
if err = models.DeleteOrphanedObjects("protected_branch", "repository", "protected_branch.repo_id=repository.id"); err != nil {
219+
logger.Critical("Error: %v whilst deleting orphaned objects", err)
220+
return err
221+
}
222+
logger.Info("%d protected branches without existing repository deleted", count)
223+
} else {
224+
logger.Warn("%d protected branches without existing repository", count)
225+
}
226+
}
227+
210228
return nil
211229
}
212230

0 commit comments

Comments
 (0)