Skip to content

Commit 1cb2e47

Browse files
Merge branch 'master' into team-permission-create-repo
# Conflicts: # models/migrations/migrations.go # models/migrations/v106.go
2 parents 0d00ba1 + 273a24f commit 1cb2e47

File tree

115 files changed

+5469
-418
lines changed

Some content is hidden

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

115 files changed

+5469
-418
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/public/js/semantic.dropdown.custom.js

contrib/systemd/gitea.service

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Type=simple
5151
User=git
5252
Group=git
5353
WorkingDirectory=/var/lib/gitea/
54-
# If using unix socket: Tells Systemd to create /run/gitea folder to home gitea.sock
55-
# Manual cration would vanish after reboot.
54+
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
55+
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
5656
#RuntimeDirectory=gitea
5757
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
5858
Restart=always

custom/conf/app.ini.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ SHOW_REGISTRATION_BUTTON = true
501501
; When adding a repo to a team or creating a new repo all team members will watch the
502502
; repo automatically if enabled
503503
AUTO_WATCH_NEW_REPOS = true
504+
; Default value for AutoWatchOnChanges
505+
; Make the user watch a repository When they commit for the first time
506+
AUTO_WATCH_ON_CHANGES = false
504507

505508
[webhook]
506509
; Hook task queue length, increase if webhook shooting starts hanging
@@ -511,6 +514,10 @@ DELIVER_TIMEOUT = 5
511514
SKIP_TLS_VERIFY = false
512515
; Number of history information in each page
513516
PAGING_NUM = 10
517+
; Proxy server URL, support http://, https//, socks://, blank will follow environment http_proxy/https_proxy
518+
PROXY_URL =
519+
; Comma separated list of host names requiring proxy. Glob patterns (*) are accepted; use ** to match all hosts.
520+
PROXY_HOSTS =
514521

515522
[mailer]
516523
ENABLED = false

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ relation to port exhaustion.
303303
on this instance.
304304
- `SHOW_REGISTRATION_BUTTON`: **! DISABLE\_REGISTRATION**: Show Registration Button
305305
- `AUTO_WATCH_NEW_REPOS`: **true**: Enable this to let all organisation users watch new repos when they are created
306+
- `AUTO_WATCH_ON_CHANGES`: **false**: Enable this to make users watch a repository after their first commit to it
306307
- `DEFAULT_ORG_VISIBILITY`: **public**: Set default visibility mode for organisations, either "public", "limited" or "private".
307308
- `DEFAULT_ORG_MEMBER_VISIBLE`: **false** True will make the membership of the users visible when added to the organisation.
308309

@@ -312,6 +313,8 @@ relation to port exhaustion.
312313
- `DELIVER_TIMEOUT`: **5**: Delivery timeout (sec) for shooting webhooks.
313314
- `SKIP_TLS_VERIFY`: **false**: Allow insecure certification.
314315
- `PAGING_NUM`: **10**: Number of webhook history events that are shown in one page.
316+
- `PROXY_URL`: ****: Proxy server URL, support http://, https//, socks://, blank will follow environment http_proxy/https_proxy
317+
- `PROXY_HOSTS`: ****: Comma separated list of host names requiring proxy. Glob patterns (*) are accepted; use ** to match all hosts.
315318

316319
## Mailer (`mailer`)
317320

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ menu:
129129
- `DELIVER_TIMEOUT`: 请求webhooks的超时时间,单位秒。
130130
- `SKIP_TLS_VERIFY`: 是否允许不安全的证书。
131131
- `PAGING_NUM`: 每页显示的Webhook 历史数量。
132+
- `PROXY_URL`: ****: 代理服务器网址,支持 http://, https//, socks://, 为空将使用环境变量中的 http_proxy/https_proxy 设置。
133+
- `PROXY_HOSTS`: ****: 逗号分隔的需要代理的域名或IP地址。支持 * 号匹配符,使用 ** 匹配所有域名和IP地址。
132134

133135
## Mailer (`mailer`)
134136

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
date: "2019-03-11T21:45:00+00:00"
3+
title: "高级: 第三方工具"
4+
slug: "third-party-tools"
5+
weight: 50
6+
toc: true
7+
draft: false
8+
menu:
9+
sidebar:
10+
parent: "advanced"
11+
name: "第三方工具"
12+
weight: 50
13+
identifier: "third-party-tools"
14+
---
15+
16+
# 第三方工具列表
17+
**注意:** 这些工具并没有经过Gitea的检验,在这里列出它们只是为了便捷.
18+
19+
*此列表并不是完整的列表,可以随时咨询如何添加!*
20+
21+
### 持续集成
22+
[BuildKite 连接器](https://github.com/techknowlogick/gitea-buildkite-connector)
23+
[Jenkins 插件](https://github.com/jenkinsci/gitea-plugin)
24+
[Gitea搭配Drone](https://docs.drone.io/installation/gitea)
25+
26+
27+
### 迁移
28+
[Gitea安装脚本](https://git.coolaj86.com/coolaj86/gitea-installer.sh)
29+
[GitHub迁移](https://gitea.com/gitea/migrator)
30+
31+
32+
### 移动端
33+
[安卓客户端GitNex](https://gitlab.com/mmarif4u/gitnex)
34+
35+
### 编辑器扩展
36+
- [Gitea的Visual Studio扩展](https://github.com/maikebing/Gitea.VisualStudio)[Visual Studio 扩展市场](https://marketplace.visualstudio.com/items?itemName=MysticBoy.GiteaExtensionforVisualStudio) 下载

docs/content/doc/help/faq.en-us.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Also see [Support Options]({{< relref "doc/help/seek-help.en-us.md" >}})
4343
* [Missing releases after migration repository with tags](#missing-releases-after-migrating-repository-with-tags)
4444
* [LFS Issues](#lfs-issues)
4545
* [How can I create users before starting Gitea](#how-can-i-create-users-before-starting-gitea)
46+
* [How can I enable password reset](#how-can-i-enable-password-reset)
47+
* [How can a user's password be changed](#how-can-a-user-s-password-be-changed)
4648

4749

4850
## Difference between 1.x and 1.x.x downloads
@@ -275,4 +277,17 @@ By default, your LFS token will expire after 20 minutes. If you have a slow conn
275277
You may want to set this value to `60m` or `120m`.
276278

277279
## How can I create users before starting Gitea
278-
Gitea provides a sub-command `gitea migrate` to initialize the database, after which you can use the [admin CLI commands]({{< relref "doc/usage/command-line.en-us.md" >}}) to add users like normal.
280+
Gitea provides a sub-command `gitea migrate` to initialize the database, after which you can use the [admin CLI commands]({{< relref "doc/usage/command-line.en-us.md#admin" >}}) to add users like normal.
281+
282+
## How can I enable password reset
283+
There is no setting for password resets. It is enabled when a [mail service]({{< relref "doc/usage/email-setup.en-us.md" >}}) is configured, and disabled otherwise.
284+
285+
## How can a user's password be changed
286+
- As an **admin**, you can change any user's password (and optionally force them to change it on next login)...
287+
- By navigating to your `Site Administration -> User Accounts` page and editing a user.
288+
- By using the [admin CLI commands]({{< relref "doc/usage/command-line.en-us.md#admin" >}}).
289+
Keep in mind most commands will also need a [global flag]({{< relref "doc/usage/command-line.en-us.md#global-options" >}}) to point the CLI at the correct configuration.
290+
- As a **user** you can change it...
291+
- In your account `Settings -> Account` page (this method **requires** you to know your current password).
292+
- By using the `Forgot Password` link.
293+
If the `Forgot Password/Account Recovery` page is disabled, please contact your administrator to configure a [mail service]({{< relref "doc/usage/email-setup.en-us.md" >}}).

docs/content/doc/usage/fail2ban-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ menu:
1313
identifier: "fail2ban-setup"
1414
---
1515

16-
# Fail2ban setup to block users after failed login attemts
16+
# Fail2ban setup to block users after failed login attempts
1717

1818
**Remember that fail2ban is powerful and can cause lots of issues if you do it incorrectly, so make
1919
sure to test this before relying on it so you don't lock yourself out.**

integrations/api_repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
334334
resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict)
335335
respJSON := map[string]string{}
336336
DecodeJSON(t, resp, &respJSON)
337-
assert.Equal(t, respJSON["message"], "The repository with the same name already exists.")
337+
assert.Equal(t, "The repository with the same name already exists.", respJSON["message"])
338338
})
339339
}
340340

integrations/api_team_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"testing"
1212

1313
"code.gitea.io/gitea/models"
14+
"code.gitea.io/gitea/modules/convert"
1415
api "code.gitea.io/gitea/modules/structs"
15-
"code.gitea.io/gitea/routers/api/v1/convert"
1616

1717
"github.com/stretchr/testify/assert"
1818
)

integrations/api_team_user_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"time"
1111

1212
"code.gitea.io/gitea/models"
13+
"code.gitea.io/gitea/modules/convert"
1314
api "code.gitea.io/gitea/modules/structs"
14-
"code.gitea.io/gitea/routers/api/v1/convert"
1515
"github.com/stretchr/testify/assert"
1616
)
1717

integrations/pull_merge_test.go

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
package integrations
66

77
import (
8+
"bytes"
9+
"fmt"
810
"net/http"
911
"net/http/httptest"
1012
"net/url"
13+
"os"
1114
"path"
1215
"strings"
1316
"testing"
17+
"time"
1418

1519
"code.gitea.io/gitea/models"
20+
"code.gitea.io/gitea/modules/git"
21+
api "code.gitea.io/gitea/modules/structs"
1622
"code.gitea.io/gitea/modules/test"
23+
"code.gitea.io/gitea/services/pull"
1724

1825
"github.com/stretchr/testify/assert"
1926
"github.com/unknwon/i18n"
@@ -202,3 +209,133 @@ func TestCantMergeWorkInProgress(t *testing.T) {
202209
assert.Equal(t, replacer.Replace(expected), text, "Unable to find WIP text")
203210
})
204211
}
212+
213+
func TestCantMergeConflict(t *testing.T) {
214+
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
215+
prepareTestEnv(t)
216+
session := loginUser(t, "user1")
217+
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
218+
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "conflict", "README.md", "Hello, World (Edited Once)\n")
219+
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "base", "README.md", "Hello, World (Edited Twice)\n")
220+
221+
// Use API to create a conflicting pr
222+
token := getTokenForLoggedInUser(t, session)
223+
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s", "user1", "repo1", token), &api.CreatePullRequestOption{
224+
Head: "conflict",
225+
Base: "base",
226+
Title: "create a conflicting pr",
227+
})
228+
session.MakeRequest(t, req, 201)
229+
230+
// Now this PR will be marked conflict - or at least a race will do - so drop down to pure code at this point...
231+
user1 := models.AssertExistsAndLoadBean(t, &models.User{
232+
Name: "user1",
233+
}).(*models.User)
234+
repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{
235+
OwnerID: user1.ID,
236+
Name: "repo1",
237+
}).(*models.Repository)
238+
239+
pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{
240+
HeadRepoID: repo1.ID,
241+
BaseRepoID: repo1.ID,
242+
HeadBranch: "conflict",
243+
BaseBranch: "base",
244+
}).(*models.PullRequest)
245+
246+
gitRepo, err := git.OpenRepository(models.RepoPath(user1.Name, repo1.Name))
247+
assert.NoError(t, err)
248+
249+
err = pull.Merge(pr, user1, gitRepo, models.MergeStyleMerge, "CONFLICT")
250+
assert.Error(t, err, "Merge should return an error due to conflict")
251+
assert.True(t, models.IsErrMergeConflicts(err), "Merge error is not a conflict error")
252+
253+
err = pull.Merge(pr, user1, gitRepo, models.MergeStyleRebase, "CONFLICT")
254+
assert.Error(t, err, "Merge should return an error due to conflict")
255+
assert.True(t, models.IsErrRebaseConflicts(err), "Merge error is not a conflict error")
256+
})
257+
}
258+
259+
func TestCantMergeUnrelated(t *testing.T) {
260+
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
261+
prepareTestEnv(t)
262+
session := loginUser(t, "user1")
263+
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
264+
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "base", "README.md", "Hello, World (Edited Twice)\n")
265+
266+
// Now we want to create a commit on a branch that is totally unrelated to our current head
267+
// Drop down to pure code at this point
268+
user1 := models.AssertExistsAndLoadBean(t, &models.User{
269+
Name: "user1",
270+
}).(*models.User)
271+
repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{
272+
OwnerID: user1.ID,
273+
Name: "repo1",
274+
}).(*models.Repository)
275+
path := models.RepoPath(user1.Name, repo1.Name)
276+
277+
_, err := git.NewCommand("read-tree", "--empty").RunInDir(path)
278+
assert.NoError(t, err)
279+
280+
stdin := bytes.NewBufferString("Unrelated File")
281+
var stdout strings.Builder
282+
err = git.NewCommand("hash-object", "-w", "--stdin").RunInDirFullPipeline(path, &stdout, nil, stdin)
283+
assert.NoError(t, err)
284+
sha := strings.TrimSpace(stdout.String())
285+
286+
_, err = git.NewCommand("update-index", "--add", "--replace", "--cacheinfo", "100644", sha, "somewher-over-the-rainbow").RunInDir(path)
287+
assert.NoError(t, err)
288+
289+
treeSha, err := git.NewCommand("write-tree").RunInDir(path)
290+
assert.NoError(t, err)
291+
treeSha = strings.TrimSpace(treeSha)
292+
293+
commitTimeStr := time.Now().Format(time.RFC3339)
294+
doerSig := user1.NewGitSig()
295+
env := append(os.Environ(),
296+
"GIT_AUTHOR_NAME="+doerSig.Name,
297+
"GIT_AUTHOR_EMAIL="+doerSig.Email,
298+
"GIT_AUTHOR_DATE="+commitTimeStr,
299+
"GIT_COMMITTER_NAME="+doerSig.Name,
300+
"GIT_COMMITTER_EMAIL="+doerSig.Email,
301+
"GIT_COMMITTER_DATE="+commitTimeStr,
302+
)
303+
304+
messageBytes := new(bytes.Buffer)
305+
_, _ = messageBytes.WriteString("Unrelated")
306+
_, _ = messageBytes.WriteString("\n")
307+
308+
stdout.Reset()
309+
err = git.NewCommand("commit-tree", treeSha).RunInDirTimeoutEnvFullPipeline(env, -1, path, &stdout, nil, messageBytes)
310+
assert.NoError(t, err)
311+
commitSha := strings.TrimSpace(stdout.String())
312+
313+
_, err = git.NewCommand("branch", "unrelated", commitSha).RunInDir(path)
314+
assert.NoError(t, err)
315+
316+
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "conflict", "README.md", "Hello, World (Edited Once)\n")
317+
318+
// Use API to create a conflicting pr
319+
token := getTokenForLoggedInUser(t, session)
320+
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s", "user1", "repo1", token), &api.CreatePullRequestOption{
321+
Head: "unrelated",
322+
Base: "base",
323+
Title: "create an unrelated pr",
324+
})
325+
session.MakeRequest(t, req, 201)
326+
327+
// Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point...
328+
gitRepo, err := git.OpenRepository(path)
329+
assert.NoError(t, err)
330+
pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{
331+
HeadRepoID: repo1.ID,
332+
BaseRepoID: repo1.ID,
333+
HeadBranch: "unrelated",
334+
BaseBranch: "base",
335+
}).(*models.PullRequest)
336+
337+
err = pull.Merge(pr, user1, gitRepo, models.MergeStyleMerge, "UNRELATED")
338+
assert.Error(t, err, "Merge should return an error due to unrelated")
339+
assert.True(t, models.IsErrMergeUnrelatedHistories(err), "Merge error is not a unrelated histories error")
340+
})
341+
}

integrations/repo_watch_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2019 The Gitea Authors. 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 integrations
6+
7+
import (
8+
"net/url"
9+
"testing"
10+
11+
"code.gitea.io/gitea/models"
12+
"code.gitea.io/gitea/modules/setting"
13+
)
14+
15+
func TestRepoWatch(t *testing.T) {
16+
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
17+
// Test round-trip auto-watch
18+
setting.Service.AutoWatchOnChanges = true
19+
session := loginUser(t, "user2")
20+
models.AssertNotExistsBean(t, &models.Watch{UserID: 2, RepoID: 3})
21+
testEditFile(t, session, "user3", "repo3", "master", "README.md", "Hello, World (Edited for watch)\n")
22+
models.AssertExistsAndLoadBean(t, &models.Watch{UserID: 2, RepoID: 3, Mode: models.RepoWatchModeAuto})
23+
})
24+
}

integrations/signup_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func TestSignup(t *testing.T) {
1919
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
2020
"user_name": "exampleUser",
2121
"email": "exampleUser@example.com",
22-
"password": "examplePassword",
23-
"retype": "examplePassword",
22+
"password": "examplePassword!1",
23+
"retype": "examplePassword!1",
2424
})
2525
MakeRequest(t, req, http.StatusFound)
2626

0 commit comments

Comments
 (0)