Skip to content

Commit fd792fd

Browse files
authored
Merge branch 'main' into issue-content-history
2 parents 177e3ac + 87505a9 commit fd792fd

File tree

135 files changed

+2073
-999
lines changed

Some content is hidden

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

135 files changed

+2073
-999
lines changed

build/generate-svg.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async function processFile(file, {prefix, fullName} = {}) {
3030
{name: 'preset-default'},
3131
{name: 'removeXMLNS'},
3232
{name: 'removeDimensions'},
33+
{name: 'prefixIds', params: {prefix: () => name}},
3334
{name: 'addClassesToSVGElement', params: {classNames: ['svg', name]}},
3435
{name: 'addAttributesToSVGElement', params: {attributes: [{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'}]}},
3536
],

cmd/admin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ var (
288288
Value: "",
289289
Usage: "Custom icon URL for OAuth2 login source",
290290
},
291+
cli.BoolFlag{
292+
Name: "skip-local-2fa",
293+
Usage: "Set to true to skip local 2fa for users authenticated by this source",
294+
},
291295
}
292296

293297
microcmdAuthUpdateOauth = cli.Command{
@@ -616,6 +620,7 @@ func parseOAuth2Config(c *cli.Context) *oauth2.Source {
616620
OpenIDConnectAutoDiscoveryURL: c.String("auto-discover-url"),
617621
CustomURLMapping: customURLMapping,
618622
IconURL: c.String("icon-url"),
623+
SkipLocalTwoFA: c.Bool("skip-local-2fa"),
619624
}
620625
}
621626

cmd/convert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func runConvert(ctx *cli.Context) error {
3131
log.Info("AppWorkPath: %s", setting.AppWorkPath)
3232
log.Info("Custom path: %s", setting.CustomPath)
3333
log.Info("Log path: %s", setting.LogRootPath)
34+
log.Info("Configuration file: %s", setting.CustomConf)
3435
setting.InitDBConfig()
3536

3637
if !setting.Database.UseMySQL {

cmd/dump_repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func runDumpRepository(ctx *cli.Context) error {
8484
log.Info("AppWorkPath: %s", setting.AppWorkPath)
8585
log.Info("Custom path: %s", setting.CustomPath)
8686
log.Info("Log path: %s", setting.LogRootPath)
87+
log.Info("Configuration file: %s", setting.CustomConf)
8788
setting.InitDBConfig()
8889

8990
var (

cmd/migrate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func runMigrate(ctx *cli.Context) error {
3232
log.Info("AppWorkPath: %s", setting.AppWorkPath)
3333
log.Info("Custom path: %s", setting.CustomPath)
3434
log.Info("Log path: %s", setting.LogRootPath)
35+
log.Info("Configuration file: %s", setting.CustomConf)
3536
setting.InitDBConfig()
3637

3738
if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {

cmd/migrate_storage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func runMigrateStorage(ctx *cli.Context) error {
114114
log.Info("AppWorkPath: %s", setting.AppWorkPath)
115115
log.Info("Custom path: %s", setting.CustomPath)
116116
log.Info("Log path: %s", setting.LogRootPath)
117+
log.Info("Configuration file: %s", setting.CustomConf)
117118
setting.InitDBConfig()
118119

119120
if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {

custom/conf/app.example.ini

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,6 @@ PATH =
800800
;; Prefix archive files by placing them in a directory named after the repository
801801
;PREFIX_ARCHIVE_FILES = true
802802
;;
803-
;; Disable the creation of new mirrors. Pre-existing mirrors remain valid.
804-
;DISABLE_MIRRORS = false
805-
;;
806803
;; Disable migrating feature.
807804
;DISABLE_MIGRATIONS = false
808805
;;
@@ -1945,6 +1942,12 @@ PATH =
19451942
;[mirror]
19461943
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19471944
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1945+
;; Enables the mirror functionality. Set to **false** to disable all mirrors.
1946+
;ENABLED = true
1947+
;; Disable the creation of **new** pull mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
1948+
;DISABLE_NEW_PULL = false
1949+
;; Disable the creation of **new** push mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
1950+
;DISABLE_NEW_PUSH = false
19481951
;; Default interval as a duration between each check
19491952
;DEFAULT_INTERVAL = 8h
19501953
;; Min interval as a duration must be > 1m
@@ -1971,8 +1974,8 @@ PATH =
19711974
;[i18n]
19721975
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19731976
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1974-
;LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,uk-UA,ja-JP,es-ES,pt-BR,pt-PT,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR
1975-
;NAMES = English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,Українська,日本語,español,português do Brasil,Português de Portugal,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어
1977+
;LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,uk-UA,ja-JP,es-ES,pt-BR,pt-PT,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR,el-GR,fa-IR,hu-HU,id-ID,ml-IN
1978+
;NAMES = English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,Українська,日本語,español,português do Brasil,Português de Portugal,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어,ελληνικά,فارسی,magyar nyelv,bahasa Indonesia,മലയാളം
19761979

19771980
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19781981
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
7373
- `DISABLED_REPO_UNITS`: **_empty_**: Comma separated list of globally disabled repo units. Allowed values: \[repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects\]
7474
- `DEFAULT_REPO_UNITS`: **repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects**: Comma separated list of default repo units. Allowed values: \[repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects\]. Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility. External wiki and issue tracker can't be enabled by default as it requires additional settings. Disabled repo units will not be added to new repositories regardless if it is in the default list.
7575
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
76-
- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid.
7776
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.
7877
- `DISABLE_STARS`: **false**: Disable stars feature.
7978
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.
@@ -876,8 +875,8 @@ NB: You must have `DISABLE_ROUTER_LOG` set to `false` for this option to take ef
876875

877876
## i18n (`i18n`)
878877

879-
- `LANGS`: **en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pt-PT,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR**: List of locales shown in language selector
880-
- `NAMES`: **English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,日本語,español,português do Brasil,Português de Portugal,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어**: Visible names corresponding to the locales
878+
- `LANGS`: **en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pt-PT,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR,el-GR,fa-IR,hu-HU,id-ID,ml-IN**: List of locales shown in language selector
879+
- `NAMES`: **English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,日本語,español,português do Brasil,Português de Portugal,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어,ελληνικά,فارسی,magyar nyelv,bahasa Indonesia,മലയാളം**: Visible names corresponding to the locales
881880

882881
## U2F (`U2F`)
883882
- `APP_ID`: **`ROOT_URL`**: Declares the facet of the application. Requires HTTPS.
@@ -955,6 +954,9 @@ Task queue configuration has been moved to `queue.task`. However, the below conf
955954

956955
## Mirror (`mirror`)
957956

957+
- `ENABLED`: **true**: Enables the mirror functionality. Set to **false** to disable all mirrors.
958+
- `DISABLE_NEW_PULL`: **false**: Disable the creation of **new** pull mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
959+
- `DISABLE_NEW_PUSH`: **false**: Disable the creation of **new** push mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
958960
- `DEFAULT_INTERVAL`: **8h**: Default interval between each check
959961
- `MIN_INTERVAL`: **10m**: Minimum interval for checking. (Must be >1m).
960962

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
date: "2021-09-02T16:00:00+08:00"
3+
title: "Upgrade from an old Gitea"
4+
slug: "upgrade-from-gitea"
5+
weight: 10
6+
toc: false
7+
draft: false
8+
menu:
9+
sidebar:
10+
parent: "upgrade"
11+
name: "From Gitea"
12+
weight: 10
13+
identifier: "upgrade-from-gitea"
14+
---
15+
16+
# Upgrade from an old Gitea
17+
18+
**Table of Contents**
19+
20+
{{< toc >}}
21+
22+
To update Gitea, download a newer version, stop the old one, perform a backup, and run the new one.
23+
Every time a Gitea instance starts up, it checks whether a database migration should be run.
24+
If a database migration is required, Gitea will take some time to complete the upgrade and then serve.
25+
26+
## Backup for downgrade
27+
28+
Gitea keeps compatibility for patch versions whose first two fields are the same (`a.b.x` -> `a.b.y`),
29+
these patch versions can be upgraded and downgraded with the same database structure.
30+
Otherwise (`a.b.?` -> `a.c.?`), a newer Gitea version will upgrade the old database
31+
to a new structure that may differ from the old version.
32+
33+
For example:
34+
35+
| From | To | Result |
36+
| --- | --- | --- |
37+
| 1.4.0 | 1.4.1 ||
38+
| 1.4.1 | 1.4.0 | ⚠️ Not recommended, take your own risk! Although it may work if the database structure doesn't change, it's highly recommended to use a backup to downgrade. |
39+
| 1.4.x | 1.5.y | ✅ Database gets upgraded. You can upgrade from 1.4.x to the latest 1.5.y directly. |
40+
| 1.5.y | 1.4.x | ❌ Database already got upgraded and can not be used for an old Gitea, use a backup to downgrade. |
41+
42+
**Since you can not run an old Gitea with an upgraded database,
43+
a backup should always be made before a database upgrade.**
44+
45+
If you use Gitea in production, it's always highly recommended to make a backup before upgrade,
46+
even if the upgrade is between patch versions.
47+
48+
Backup steps:
49+
50+
* Stop Gitea instance
51+
* Backup database
52+
* Backup Gitea config
53+
* Backup Gitea data files in `APP_DATA_PATH`
54+
* Backup Gitea external storage (eg: S3/MinIO or other storages if used)
55+
56+
If you are using cloud services or filesystems with snapshot feature,
57+
a snapshot for the Gitea data volume and related object storage is more convenient.
58+
59+
60+
## Upgrade with Docker
61+
62+
* `docker pull` the latest Gitea release.
63+
* Stop the running instance, backup data.
64+
* Use `docker` or `docker-compose` to start the newer Gitea Docker container.
65+
66+
## Upgrade from package
67+
68+
* Stop the running instance, backup data.
69+
* Use your package manager to upgrade Gitea to the latest version.
70+
* Start the Gitea instance.
71+
72+
## Upgrade from binary
73+
74+
* Download the latest Gitea binary to a temporary directory.
75+
* Stop the running instance, backup data.
76+
* Replace the installed Gitea binary with the downloaded one.
77+
* Start the Gitea instance.
78+
79+
## Take care about customized templates
80+
81+
Gitea's template structure and variables may change between releases, if you are using customized templates,
82+
do pay attention if your templates are compatible with the Gitea you are using.
83+
84+
If the customized templates don't match Gitea version, you may experience:
85+
`50x` server error, page components missing or malfunctioning, strange page layout, ...
86+
Remove or update the incompatible templates and Gitea web will work again.

docs/content/page/index.de-de.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Gitea ist ein [Gogs](http://gogs.io)-Fork.
2222

2323
## System Voraussetzungen
2424

25-
- A Raspberry Pi 3 is powerful enough to run Gitea for small workloads.
26-
- 2 CPU cores and 1GB RAM is typically sufficient for small teams/projects.
27-
- Gitea should be run with a dedicated non-root system account on UNIX-type systems.
28-
- Note: Gitea manages the `~/.ssh/authorized_keys` file. Running Gitea as a regular user could break that user's ability to log in.
29-
- [Git](https://git-scm.com/) version 1.7.2 or later is required. Version 1.9.0 or later is recommended. Also please note:
30-
- Git [large file storage](https://git-lfs.github.com/) will be available if enabled when git >= 2.1.2.
31-
- Git commit-graph rendering will be enabled automatically when git >= 2.18.
25+
- Ein Raspberry Pi 3 ist leistungsstark genug, um Gitea für kleine Belastungen laufen zu lassen.
26+
- 2 CPU Kerne und 1GB RAM sind für kleine Teams/Projekte ausreichend.
27+
- Gitea sollte unter einem seperaten nicht-root Account auf UNIX-Systemen ausgeführt werden.
28+
- Achtung: Gitea verwaltet die `~/.ssh/authorized_keys` Datei. Gitea unter einem normalen Benutzer auszuführen könnte dazu führen, dass dieser sich nicht mehr anmelden kann.
29+
- [Git](https://git-scm.com/) Version 1.7.2 oder später wird benötigt. Version 1.9.0 oder später wird empfohlen. Außerdem zu beachten:
30+
- Wenn git >= 2.1.2. und [Git large file storage](https://git-lfs.github.com/) aktiviert ist, dann wird es auch in Gitea verwendbar sein.
31+
- Wenn git >= 2.18, dann wird das Rendern von Commit-Graphen automatisch aktiviert.
3232

3333
## Browser Unterstützung
3434

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
gitea.com/go-chi/binding v0.0.0-20210301195521-1fe1c9a555e7
1010
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e
1111
gitea.com/go-chi/captcha v0.0.0-20210110083842-e7696c336a1e
12-
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee
12+
gitea.com/go-chi/session v0.0.0-20210913064732-2ac132b0fa07
1313
gitea.com/lunny/levelqueue v0.4.1
1414
github.com/Microsoft/go-winio v0.5.0 // indirect
1515
github.com/NYTimes/gziphandler v1.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e h1:zgPGaf3kXP0cVm9J0l8
4747
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0=
4848
gitea.com/go-chi/captcha v0.0.0-20210110083842-e7696c336a1e h1:YjaQU6XFicdhPN+MlGolcXO8seYY2+EY5g7vZPB17CQ=
4949
gitea.com/go-chi/captcha v0.0.0-20210110083842-e7696c336a1e/go.mod h1:nfA7JaGv3hbGQ1ktdhAsZhdS84qKffI8NMlHr+Opsog=
50-
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee h1:9U6HuKUBt/cGK6T/64dEuz0r7Yp97WAAEJvXHDlY3ws=
51-
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
50+
gitea.com/go-chi/session v0.0.0-20210913064732-2ac132b0fa07 h1:1xF0xbIgDWnBB0iURAUFCoac4KfhGDdI7y7+3/8I8i4=
51+
gitea.com/go-chi/session v0.0.0-20210913064732-2ac132b0fa07/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
5252
gitea.com/lunny/levelqueue v0.4.1 h1:RZ+AFx5gBsZuyqCvofhAkPQ9uaVDPJnsULoJZIYaJNw=
5353
gitea.com/lunny/levelqueue v0.4.1/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
5454
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=

integrations/api_settings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestAPIExposedSettings(t *testing.T) {
4343

4444
DecodeJSON(t, resp, &repo)
4545
assert.EqualValues(t, &api.GeneralRepoSettings{
46-
MirrorsDisabled: setting.Repository.DisableMirrors,
46+
MirrorsDisabled: !setting.Mirror.Enabled,
4747
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
4848
MigrationsDisabled: setting.Repository.DisableMigrations,
4949
TimeTrackingDisabled: false,

integrations/git_test.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes
365365
t.Run("PushProtectedBranch", doGitPushTestRepository(dstPath, "origin", "protected"))
366366

367367
ctx := NewAPITestContext(t, baseCtx.Username, baseCtx.Reponame)
368-
t.Run("ProtectProtectedBranchNoWhitelist", doProtectBranch(ctx, "protected", ""))
368+
t.Run("ProtectProtectedBranchNoWhitelist", doProtectBranch(ctx, "protected", "", ""))
369369
t.Run("GenerateCommit", func(t *testing.T) {
370370
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-")
371371
assert.NoError(t, err)
@@ -391,7 +391,15 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes
391391
t.Run("MergePR2", doAPIMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr2.Index))
392392
t.Run("MergePR", doAPIMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index))
393393
t.Run("PullProtected", doGitPull(dstPath, "origin", "protected"))
394-
t.Run("ProtectProtectedBranchWhitelist", doProtectBranch(ctx, "protected", baseCtx.Username))
394+
395+
t.Run("ProtectProtectedBranchUnprotectedFilePaths", doProtectBranch(ctx, "protected", "", "unprotected-file-*"))
396+
t.Run("GenerateCommit", func(t *testing.T) {
397+
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "unprotected-file-")
398+
assert.NoError(t, err)
399+
})
400+
t.Run("PushUnprotectedFilesToProtectedBranch", doGitPushTestRepository(dstPath, "origin", "protected"))
401+
402+
t.Run("ProtectProtectedBranchWhitelist", doProtectBranch(ctx, "protected", baseCtx.Username, ""))
395403

396404
t.Run("CheckoutMaster", doGitCheckoutBranch(dstPath, "master"))
397405
t.Run("CreateBranchForced", doGitCreateBranch(dstPath, "toforce"))
@@ -406,28 +414,30 @@ func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *tes
406414
}
407415
}
408416

409-
func doProtectBranch(ctx APITestContext, branch string, userToWhitelist string) func(t *testing.T) {
417+
func doProtectBranch(ctx APITestContext, branch string, userToWhitelist string, unprotectedFilePatterns string) func(t *testing.T) {
410418
// We are going to just use the owner to set the protection.
411419
return func(t *testing.T) {
412420
csrf := GetCSRF(t, ctx.Session, fmt.Sprintf("/%s/%s/settings/branches", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame)))
413421

414422
if userToWhitelist == "" {
415423
// Change branch to protected
416424
req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/branches/%s", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), url.PathEscape(branch)), map[string]string{
417-
"_csrf": csrf,
418-
"protected": "on",
425+
"_csrf": csrf,
426+
"protected": "on",
427+
"unprotected_file_patterns": unprotectedFilePatterns,
419428
})
420429
ctx.Session.MakeRequest(t, req, http.StatusFound)
421430
} else {
422431
user, err := models.GetUserByName(userToWhitelist)
423432
assert.NoError(t, err)
424433
// Change branch to protected
425434
req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/branches/%s", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), url.PathEscape(branch)), map[string]string{
426-
"_csrf": csrf,
427-
"protected": "on",
428-
"enable_push": "whitelist",
429-
"enable_whitelist": "on",
430-
"whitelist_users": strconv.FormatInt(user.ID, 10),
435+
"_csrf": csrf,
436+
"protected": "on",
437+
"enable_push": "whitelist",
438+
"enable_whitelist": "on",
439+
"whitelist_users": strconv.FormatInt(user.ID, 10),
440+
"unprotected_file_patterns": unprotectedFilePatterns,
431441
})
432442
ctx.Session.MakeRequest(t, req, http.StatusFound)
433443
}

models/attachment.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@
55
package models
66

77
import (
8-
"bytes"
98
"fmt"
10-
"io"
119
"path"
1210

1311
"code.gitea.io/gitea/modules/setting"
1412
"code.gitea.io/gitea/modules/storage"
1513
"code.gitea.io/gitea/modules/timeutil"
1614

17-
gouuid "github.com/google/uuid"
1815
"xorm.io/xorm"
1916
)
2017

2118
// Attachment represent a attachment of issue/comment/release.
2219
type Attachment struct {
2320
ID int64 `xorm:"pk autoincr"`
2421
UUID string `xorm:"uuid UNIQUE"`
25-
IssueID int64 `xorm:"INDEX"`
26-
ReleaseID int64 `xorm:"INDEX"`
22+
RepoID int64 `xorm:"INDEX"` // this should not be zero
23+
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
24+
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
2725
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
2826
CommentID int64
2927
Name string
@@ -81,23 +79,6 @@ func (a *Attachment) LinkedRepository() (*Repository, UnitType, error) {
8179
return nil, -1, nil
8280
}
8381

84-
// NewAttachment creates a new attachment object.
85-
func NewAttachment(attach *Attachment, buf []byte, file io.Reader) (_ *Attachment, err error) {
86-
attach.UUID = gouuid.New().String()
87-
88-
size, err := storage.Attachments.Save(attach.RelativePath(), io.MultiReader(bytes.NewReader(buf), file), -1)
89-
if err != nil {
90-
return nil, fmt.Errorf("Create: %v", err)
91-
}
92-
attach.Size = size
93-
94-
if _, err := x.Insert(attach); err != nil {
95-
return nil, err
96-
}
97-
98-
return attach, nil
99-
}
100-
10182
// GetAttachmentByID returns attachment by given id
10283
func GetAttachmentByID(id int64) (*Attachment, error) {
10384
return getAttachmentByID(x, id)

0 commit comments

Comments
 (0)