Skip to content

Commit 59f694b

Browse files
authored
Merge pull request #2 from go-gitea/master
Merge branch 'master' of https://github.com/go-gitea/gitea
2 parents 743c80e + e90e122 commit 59f694b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1191
-322
lines changed

.drone.yml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ workspace:
1313
steps:
1414
- name: deps-frontend
1515
pull: always
16-
image: node:12
16+
image: node:14
1717
commands:
1818
- make node_modules
1919

2020
- name: lint-frontend
2121
pull: always
22-
image: node:12
22+
image: node:14
2323
commands:
2424
- make lint-frontend
2525
depends_on: [deps-frontend]
@@ -36,7 +36,7 @@ steps:
3636

3737
- name: checks-frontend
3838
pull: always
39-
image: node:12
39+
image: node:14
4040
commands:
4141
- make checks-frontend
4242
depends_on: [deps-frontend]
@@ -50,7 +50,7 @@ steps:
5050

5151
- name: build-frontend
5252
pull: always
53-
image: node:10 # this step is kept at the lowest version of node that we support
53+
image: node:14
5454
commands:
5555
- make frontend
5656
depends_on: [lint-frontend]
@@ -447,23 +447,13 @@ steps:
447447
commands:
448448
- git fetch --tags --force
449449

450-
- name: static-windows
451-
pull: always
452-
image: techknowlogick/xgo:go-1.14.x
453-
commands:
454-
- apt update && apt -y install curl
455-
- curl -sL https://deb.nodesource.com/setup_12.x | bash - && apt -y install nodejs
456-
- export PATH=$PATH:$GOPATH/bin
457-
- make frontend generate release-windows
458-
environment:
459-
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
460-
TAGS: bindata sqlite sqlite_unlock_notify
461-
462450
- name: static
463451
pull: always
464452
image: techknowlogick/xgo:go-1.15.x
465453
commands:
466-
- make release-linux release-darwin release-copy release-compress release-sources release-docs release-check
454+
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs
455+
- export PATH=$PATH:$GOPATH/bin
456+
- make release
467457
environment:
468458
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
469459
TAGS: bindata sqlite sqlite_unlock_notify
@@ -558,8 +548,7 @@ steps:
558548
pull: always
559549
image: techknowlogick/xgo:go-1.15.x
560550
commands:
561-
- apt update && apt -y install curl
562-
- curl -sL https://deb.nodesource.com/setup_12.x | bash - && apt -y install nodejs
551+
- curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs
563552
- export PATH=$PATH:$GOPATH/bin
564553
- make release
565554
environment:

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trim_trailing_whitespace = false
1111

1212
[*.{go,tmpl,html}]
1313
indent_style = tab
14-
indent_size = 4
14+
indent_size = 2
1515

1616
[*.{less,css}]
1717
indent_style = space

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ ifeq ($(HAS_GO), GO)
4242
endif
4343

4444
ifeq ($(OS), Windows_NT)
45+
GOFLAGS := -v -buildmode=exe
4546
EXECUTABLE ?= gitea.exe
4647
else
48+
GOFLAGS := -v
4749
EXECUTABLE ?= gitea
4850
endif
4951

@@ -55,7 +57,6 @@ endif
5557

5658
GOFMT ?= gofmt -s
5759

58-
GOFLAGS := -v
5960
EXTRA_GOFLAGS ?=
6061

6162
MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
@@ -556,7 +557,7 @@ release-windows: | $(DIST_DIRS)
556557
GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
557558
fi
558559
@echo "Warning: windows version is built using golang 1.14"
559-
CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go go-1.14.x -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
560+
CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
560561
ifeq ($(CI),drone)
561562
cp /build/* $(DIST)/binaries
562563
endif
@@ -680,7 +681,7 @@ pr\#%: clean-all
680681
golangci-lint:
681682
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
682683
export BINARY="golangci-lint"; \
683-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.24.0; \
684+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.30.0; \
684685
fi
685686
golangci-lint run --timeout 5m
686687

SECURITY.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Reporting security issues
2+
3+
The Gitea maintainers take security seriously.
4+
If you discover a security issue, please bring it to their attention right away!
5+
6+
### Reporting a Vulnerability
7+
8+
Please **DO NOT** file a public issue, instead send your report privately to `[email protected]`.
9+
10+
Security reports are greatly appreciated and we will publicly thank you for it, although we keep your name confidential if you request it.

cmd/doctor.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ var checklist = []check{
127127
isDefault: false,
128128
f: runDoctorUserStarNum,
129129
},
130+
{
131+
title: "Enable push options",
132+
name: "enable-push-options",
133+
isDefault: false,
134+
f: runDoctorEnablePushOptions,
135+
},
130136
// more checks please append here
131137
}
132138

@@ -605,3 +611,28 @@ func runDoctorCheckDBConsistency(ctx *cli.Context) ([]string, error) {
605611

606612
return results, nil
607613
}
614+
615+
func runDoctorEnablePushOptions(ctx *cli.Context) ([]string, error) {
616+
numRepos := 0
617+
_, err := iterateRepositories(func(repo *models.Repository) ([]string, error) {
618+
numRepos++
619+
r, err := git.OpenRepository(repo.RepoPath())
620+
if err != nil {
621+
return nil, err
622+
}
623+
defer r.Close()
624+
625+
if ctx.Bool("fix") {
626+
_, err := git.NewCommand("config", "receive.advertisePushOptions", "true").RunInDir(r.Path)
627+
return nil, err
628+
}
629+
630+
return nil, nil
631+
})
632+
633+
var prefix string
634+
if !ctx.Bool("fix") {
635+
prefix = "DRY RUN: "
636+
}
637+
return []string{fmt.Sprintf("%sEnabled push options for %d repositories.", prefix, numRepos)}, err
638+
}

cmd/hook.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ Gitea or set your environment appropriately.`, "")
178178
GitAlternativeObjectDirectories: os.Getenv(private.GitAlternativeObjectDirectories),
179179
GitObjectDirectory: os.Getenv(private.GitObjectDirectory),
180180
GitQuarantinePath: os.Getenv(private.GitQuarantinePath),
181+
GitPushOptions: pushOptions(),
181182
ProtectedBranchID: prID,
182183
IsDeployKey: isDeployKey,
183184
}
@@ -326,6 +327,7 @@ Gitea or set your environment appropriately.`, "")
326327
GitAlternativeObjectDirectories: os.Getenv(private.GitAlternativeObjectDirectories),
327328
GitObjectDirectory: os.Getenv(private.GitObjectDirectory),
328329
GitQuarantinePath: os.Getenv(private.GitQuarantinePath),
330+
GitPushOptions: pushOptions(),
329331
}
330332
oldCommitIDs := make([]string, hookBatchSize)
331333
newCommitIDs := make([]string, hookBatchSize)
@@ -438,3 +440,17 @@ func hookPrintResults(results []private.HookPostReceiveBranchResult) {
438440
os.Stderr.Sync()
439441
}
440442
}
443+
444+
func pushOptions() map[string]string {
445+
opts := make(map[string]string)
446+
if pushCount, err := strconv.Atoi(os.Getenv(private.GitPushOptionCount)); err == nil {
447+
for idx := 0; idx < pushCount; idx++ {
448+
opt := os.Getenv(fmt.Sprintf("GIT_PUSH_OPTION_%d", idx))
449+
kv := strings.SplitN(opt, "=", 2)
450+
if len(kv) == 2 {
451+
opts[kv[0]] = kv[1]
452+
}
453+
}
454+
}
455+
return opts
456+
}

custom/conf/app.example.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,9 @@ DISABLE_GIT_HOOKS = false
497497
; Set to false to allow pushes to gitea repositories despite having an incomplete environment - NOT RECOMMENDED
498498
ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET = true
499499
;Comma separated list of character classes required to pass minimum complexity.
500-
;If left empty or no valid values are specified, the default values ("lower,upper,digit,spec") will be used.
501-
;Use "off" to disable checking.
502-
PASSWORD_COMPLEXITY = lower,upper,digit,spec
500+
;If left empty or no valid values are specified, the default is off (no checking)
501+
;Classes include "lower,upper,digit,spec"
502+
PASSWORD_COMPLEXITY = off
503503
; Password Hash algorithm, either "pbkdf2", "argon2", "scrypt" or "bcrypt"
504504
PASSWORD_HASH_ALGO = pbkdf2
505505
; Set false to allow JavaScript to read CSRF cookie
@@ -971,8 +971,8 @@ ACCESS_TOKEN_EXPIRATION_TIME=3600
971971
REFRESH_TOKEN_EXPIRATION_TIME=730
972972
; Check if refresh token got already used
973973
INVALIDATE_REFRESH_TOKENS=false
974-
; OAuth2 authentication secret for access and refresh tokens, change this to a unique string.
975-
JWT_SECRET=Bk0yK7Y9g_p56v86KaHqjSbxvNvu3SbKoOdOt2ZcXvU
974+
; OAuth2 authentication secret for access and refresh tokens, change this yourself to a unique string. CLI generate option is helpful in this case. https://docs.gitea.io/en-us/command-line/#generate
975+
JWT_SECRET=
976976
; Maximum length of oauth2 token/cookie stored on server
977977
MAX_TOKEN_LENGTH=32767
978978

@@ -985,7 +985,7 @@ NAMES = English,简体中文,繁體中文(香港),繁體中文(台灣),D
985985
; Two Factor authentication with security keys
986986
; https://developers.yubico.com/U2F/App_ID.html
987987
;APP_ID = http://localhost:3000/
988-
; Comma seperated list of trusted facets
988+
; Comma separated list of trusted facets
989989
;TRUSTED_FACETS = http://localhost:3000/
990990

991991
; Extension mapping to highlight class

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ set name for unique queues. Individual queues will default to
323323
- `INTERNAL_TOKEN_URI`: **<empty>**: Instead of defining internal token in the configuration, this configuration option can be used to give Gitea a path to a file that contains the internal token (example value: `file:/etc/gitea/internal_token`)
324324
- `PASSWORD_HASH_ALGO`: **pbkdf2**: The hash algorithm to use \[pbkdf2, argon2, scrypt, bcrypt\].
325325
- `CSRF_COOKIE_HTTP_ONLY`: **true**: Set false to allow JavaScript to read CSRF cookie.
326-
- `PASSWORD_COMPLEXITY`: **lower,upper,digit,spec**: Comma separated list of character classes required to pass minimum complexity. If left empty or no valid values are specified, the default values will be used. Possible values are:
326+
- `PASSWORD_COMPLEXITY`: **off**: Comma separated list of character classes required to pass minimum complexity. If left empty or no valid values are specified, checking is disabled (off):
327327
- lower - use one or more lower latin characters
328328
- upper - use one or more upper latin characters
329329
- digit - use one or more digits
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
date: "2020-07-06T16:00:00+02:00"
3+
title: "Usage: Push Options"
4+
slug: "push-options"
5+
weight: 15
6+
toc: true
7+
draft: false
8+
menu:
9+
sidebar:
10+
parent: "usage"
11+
name: "Push Options"
12+
weight: 15
13+
identifier: "push-options"
14+
---
15+
16+
# Push Options
17+
18+
In Gitea `1.13`, support for some [push options](https://git-scm.com/docs/git-push#Documentation/git-push.txt--oltoptiongt)
19+
were added.
20+
21+
22+
## Supported Options
23+
24+
- `repo.private` (true|false) - Change the repository's visibility.
25+
This is particularly useful when combined with push-to-create.
26+
- `repo.template` (true|false) - Change whether the repository is a template.
27+
28+
Example of changing a repository's visibility to public:
29+
```shell
30+
git push -o repo.private=false -u origin master
31+
```

integrations/repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestViewRepoWithSymlinks(t *testing.T) {
148148
resp := session.MakeRequest(t, req, http.StatusOK)
149149

150150
htmlDoc := NewHTMLParser(t, resp.Body)
151-
files := htmlDoc.doc.Find("#repo-files-table > TBODY > TR > TD.name > SPAN")
151+
files := htmlDoc.doc.Find("#repo-files-table > TBODY > TR > TD.name")
152152
items := files.Map(func(i int, s *goquery.Selection) string {
153153
cls, _ := s.Find("SVG").Attr("class")
154154
file := strings.Trim(s.Find("A").Text(), " \t\n")

models/avatar.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,18 @@ func AvatarLink(email string) string {
4141
Email: lowerEmail,
4242
Hash: sum,
4343
}
44-
_, _ = x.Insert(emailHash)
44+
// OK we're going to open a session just because I think that that might hide away any problems with postgres reporting errors
45+
sess := x.NewSession()
46+
defer sess.Close()
47+
if err := sess.Begin(); err != nil {
48+
// we don't care about any DB problem just return the lowerEmail
49+
return lowerEmail, nil
50+
}
51+
_, _ = sess.Insert(emailHash)
52+
if err := sess.Commit(); err != nil {
53+
// Seriously we don't care about any DB problems just return the lowerEmail - we expect the transaction to fail most of the time
54+
return lowerEmail, nil
55+
}
4556
return lowerEmail, nil
4657
})
4758
return setting.AppSubURL + "/avatar/" + url.PathEscape(sum)

models/branches.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
9898
}
9999

100100
// IsUserMergeWhitelisted checks if some user is whitelisted to merge to this branch
101-
func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64) bool {
101+
func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64, permissionInRepo Permission) bool {
102102
if !protectBranch.EnableMergeWhitelist {
103-
return true
103+
// Then we need to fall back on whether the user has write permission
104+
return permissionInRepo.CanWrite(UnitTypeCode)
104105
}
105106

106107
if base.Int64sContains(protectBranch.MergeWhitelistUserIDs, userID) {

0 commit comments

Comments
 (0)