Skip to content

Commit 1264f90

Browse files
committed
Merge branch 'master' into issue-4173-alternative-fix
2 parents 5a0c8f3 + 296814e commit 1264f90

Some content is hidden

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

53 files changed

+2709
-1669
lines changed

.drone.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,42 @@ pipeline:
195195
when:
196196
event: [ push, tag, pull_request ]
197197

198+
bench-sqlite:
199+
image: golang:1.11
200+
pull: true
201+
group: bench
202+
commands:
203+
- make bench-sqlite
204+
when:
205+
event: [ tag ]
206+
207+
bench-mysql:
208+
image: golang:1.11
209+
pull: true
210+
group: bench
211+
commands:
212+
- make bench-mysql
213+
when:
214+
event: [ tag ]
215+
216+
bench-mssql:
217+
image: golang:1.11
218+
pull: true
219+
group: bench
220+
commands:
221+
- make bench-mssql
222+
when:
223+
event: [ tag ]
224+
225+
bench-pgsql:
226+
image: golang:1.11
227+
pull: true
228+
group: bench
229+
commands:
230+
- make bench-pgsql
231+
when:
232+
event: [ tag ]
233+
198234
generate-coverage:
199235
image: golang:1.11
200236
pull: true

.editorconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# http://editorconfig.org
2-
32
root = true
43

54
[*]
@@ -19,7 +18,7 @@ indent_size = 4
1918
indent_style = space
2019
indent_size = 4
2120

22-
[*.{yml}]
21+
[*.{yml,json}]
2322
indent_style = space
2423
indent_size = 2
2524

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ bench-sqlite: integrations.sqlite.test
252252
bench-mysql: integrations.test generate-ini
253253
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
254254

255+
.PHONY: bench-mssql
256+
bench-mssql: integrations.test generate-ini
257+
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
258+
255259
.PHONY: bench-pgsql
256260
bench-pgsql: integrations.test generate-ini
257261
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
@@ -361,8 +365,10 @@ stylesheets-check: generate-stylesheets
361365

362366
.PHONY: generate-stylesheets
363367
generate-stylesheets:
368+
$(eval BROWSERS := "> 2%, last 2 firefox versions, last 2 safari versions")
364369
node_modules/.bin/lessc --clean-css public/less/index.less public/css/index.css
365370
$(foreach file, $(filter-out public/less/themes/_base.less, $(wildcard public/less/themes/*)),node_modules/.bin/lessc --clean-css public/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)
371+
$(foreach file, $(wildcard public/css/*),node_modules/.bin/postcss --use autoprefixer --autoprefixer.browsers $(BROWSERS) -o $(file) $(file);)
366372

367373
.PHONY: swagger-ui
368374
swagger-ui:

custom/conf/app.ini.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ DISABLE_HTTP_GIT = false
3636
ACCESS_CONTROL_ALLOW_ORIGIN =
3737
; Force ssh:// clone url instead of scp-style uri when default SSH port is used
3838
USE_COMPAT_SSH_URI = false
39+
; Close issues as long as a commit on any branch marks it as fixed
40+
DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = false
3941

4042
[repository.editor]
4143
; List of file extensions for which lines should be wrapped in the CodeMirror editor
@@ -610,6 +612,7 @@ GC_ARGS =
610612

611613
; Operation timeout in seconds
612614
[git.timeout]
615+
DEFAULT = 360
613616
MIGRATE = 600
614617
MIRROR = 300
615618
CLONE = 300

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
6565
- `ACCESS_CONTROL_ALLOW_ORIGIN`: **\<empty\>**: Value for Access-Control-Allow-Origin header,
6666
default is not to present. **WARNING**: This maybe harmful to you website if you do not
6767
give it a right value.
68+
- `DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH`: **false**: Close an issue if a commit on a non default branch marks it as closed.
6869

6970
### Repository - Pull Request (`repository.pull-request`)
7071
- `WORK_IN_PROGRESS_PREFIXES`: **WIP:,\[WIP\]**: List of prefixes used in Pull Request
@@ -316,6 +317,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
316317
- `GC_ARGS`: **\<empty\>**: Arguments for command `git gc`, e.g. `--aggressive --auto`. See more on http://git-scm.com/docs/git-gc/
317318

318319
## Git - Timeout settings (`git.timeout`)
320+
- `DEFAUlT`: **360**: Git operations default timeout seconds.
319321
- `MIGRATE`: **600**: Migrate external repositories timeout seconds.
320322
- `MIRROR`: **300**: Mirror external repositories timeout seconds.
321323
- `CLONE`: **300**: Git clone from internal repositories timeout seconds.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ menu:
188188
- `GC_ARGS`: 执行 `git gc` 命令的参数, 比如: `--aggressive --auto`
189189

190190
## Git - 超时设置 (`git.timeout`)
191+
192+
- `DEFAUlT`: **360**: Git操作默认超时时间,单位秒
191193
- `MIGRATE`: **600**: 迁移外部仓库时的超时时间,单位秒
192194
- `MIRROR`: **300**: 镜像外部仓库的超时时间,单位秒
193195
- `CLONE`: **300**: 内部仓库间克隆的超时时间,单位秒

docs/content/doc/usage/command-line.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Admin operations:
5757
- `--admin`: If provided, this makes the user an admin. Optional.
5858
- `--config path`: Gitea configuration file path. Optional. (default: custom/conf/app.ini).
5959
- `--must-change-password`: If provided, the created user will be required to choose a newer password after
60-
the initial login. Optional. (default: false).
60+
the initial login. Optional. (default: true).
6161
- ``--random-password``: If provided, a randomly generated password will be used as the password of
6262
the created user. The value of `--password` will be discarded. Optional.
6363
- `--random-password-length`: If provided, it will be used to configure the length of the randomly

models/action.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra
539539
}
540540

541541
// Change issue status only if the commit has been pushed to the default branch.
542-
if repo.DefaultBranch != branchName {
542+
// and if the repo is configured to allow only that
543+
if repo.DefaultBranch != branchName && !repo.CloseIssuesViaCommitInAnyBranch {
543544
continue
544545
}
545546

models/action_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,40 @@ func TestUpdateIssuesCommit(t *testing.T) {
260260
CheckConsistencyFor(t, &Action{})
261261
}
262262

263+
func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
264+
assert.NoError(t, PrepareTestDatabase())
265+
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
266+
267+
// Test that push to a non-default branch closes an issue.
268+
pushCommits := []*PushCommit{
269+
{
270+
Sha1: "abcdef1",
271+
CommitterEmail: "[email protected]",
272+
CommitterName: "User Two",
273+
AuthorEmail: "[email protected]",
274+
AuthorName: "User Four",
275+
Message: "close #2",
276+
},
277+
}
278+
279+
repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
280+
commentBean := &Comment{
281+
Type: CommentTypeCommitRef,
282+
CommitSHA: "abcdef1",
283+
PosterID: user.ID,
284+
IssueID: 7,
285+
}
286+
287+
issueBean := &Issue{RepoID: repo.ID, Index: 2, ID: 7}
288+
289+
AssertNotExistsBean(t, commentBean)
290+
AssertNotExistsBean(t, issueBean, "is_closed=1")
291+
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
292+
AssertExistsAndLoadBean(t, commentBean)
293+
AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
294+
CheckConsistencyFor(t, &Action{})
295+
}
296+
263297
func testCorrectRepoAction(t *testing.T, opts CommitRepoActionOptions, actionBean *Action) {
264298
AssertNotExistsBean(t, actionBean)
265299
assert.NoError(t, CommitRepoAction(opts))

models/fixtures/issue.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,16 @@
7373
num_comments: 0
7474
created_unix: 946684850
7575
updated_unix: 978307200
76+
77+
-
78+
id: 7
79+
repo_id: 2
80+
index: 2
81+
poster_id: 2
82+
name: issue7
83+
content: content for the seventh issue
84+
is_closed: false
85+
is_pull: false
86+
created_unix: 946684830
87+
updated_unix: 978307200
88+

models/fixtures/repository.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
lower_name: repo2
1818
name: repo2
1919
is_private: true
20-
num_issues: 1
20+
num_issues: 2
2121
num_closed_issues: 1
2222
num_pulls: 0
2323
num_closed_pulls: 0
2424
num_stars: 1
25+
close_issues_via_commit_in_any_branch: true
2526

2627
-
2728
id: 3

models/issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func TestGetUserIssueStats(t *testing.T) {
275275
YourRepositoriesCount: 2,
276276
AssignCount: 0,
277277
CreateCount: 2,
278-
OpenCount: 1,
278+
OpenCount: 2,
279279
ClosedCount: 2,
280280
},
281281
},

models/lfs.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package models
22

33
import (
4+
"crypto/sha256"
5+
"encoding/hex"
46
"errors"
7+
"fmt"
8+
"io"
59

610
"code.gitea.io/gitea/modules/util"
711
)
@@ -16,6 +20,11 @@ type LFSMetaObject struct {
1620
CreatedUnix util.TimeStamp `xorm:"created"`
1721
}
1822

23+
// Pointer returns the string representation of an LFS pointer file
24+
func (m *LFSMetaObject) Pointer() string {
25+
return fmt.Sprintf("%s\n%s%s\nsize %d\n", LFSMetaFileIdentifier, LFSMetaFileOidPrefix, m.Oid, m.Size)
26+
}
27+
1928
// LFSTokenResponse defines the JSON structure in which the JWT token is stored.
2029
// This structure is fetched via SSH and passed by the Git LFS client to the server
2130
// endpoint for authorization.
@@ -67,6 +76,16 @@ func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) {
6776
return m, sess.Commit()
6877
}
6978

79+
// GenerateLFSOid generates a Sha256Sum to represent an oid for arbitrary content
80+
func GenerateLFSOid(content io.Reader) (string, error) {
81+
h := sha256.New()
82+
if _, err := io.Copy(h, content); err != nil {
83+
return "", err
84+
}
85+
sum := h.Sum(nil)
86+
return hex.EncodeToString(sum), nil
87+
}
88+
7089
// GetLFSMetaObjectByOid selects a LFSMetaObject entry from database by its OID.
7190
// It may return ErrLFSObjectNotExist or a database error. If the error is nil,
7291
// the returned pointer is a valid LFSMetaObject.

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ var migrations = []Migration{
210210
NewMigration("add theme to users", addUserDefaultTheme),
211211
// v78 -> v79
212212
NewMigration("rename repo is_bare to repo is_empty", renameRepoIsBareToIsEmpty),
213+
// v79 -> v80
214+
NewMigration("add can close issues via commit in any branch", addCanCloseIssuesViaCommitInAnyBranch),
213215
}
214216

215217
// Migrate database to current version

models/migrations/v79.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 migrations
6+
7+
import (
8+
"code.gitea.io/gitea/modules/setting"
9+
10+
"github.com/go-xorm/xorm"
11+
)
12+
13+
func addCanCloseIssuesViaCommitInAnyBranch(x *xorm.Engine) error {
14+
15+
type Repository struct {
16+
ID int64 `xorm:"pk autoincr"`
17+
CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"`
18+
}
19+
20+
if err := x.Sync2(new(Repository)); err != nil {
21+
return err
22+
}
23+
24+
_, err := x.Exec("UPDATE repository SET close_issues_via_commit_in_any_branch = ?",
25+
setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch)
26+
return err
27+
}

models/repo.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,14 @@ type Repository struct {
197197
ExternalMetas map[string]string `xorm:"-"`
198198
Units []*RepoUnit `xorm:"-"`
199199

200-
IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
201-
ForkID int64 `xorm:"INDEX"`
202-
BaseRepo *Repository `xorm:"-"`
203-
Size int64 `xorm:"NOT NULL DEFAULT 0"`
204-
IndexerStatus *RepoIndexerStatus `xorm:"-"`
205-
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`
206-
Topics []string `xorm:"TEXT JSON"`
200+
IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
201+
ForkID int64 `xorm:"INDEX"`
202+
BaseRepo *Repository `xorm:"-"`
203+
Size int64 `xorm:"NOT NULL DEFAULT 0"`
204+
IndexerStatus *RepoIndexerStatus `xorm:"-"`
205+
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`
206+
CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"`
207+
Topics []string `xorm:"TEXT JSON"`
207208

208209
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
209210
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
@@ -1373,13 +1374,14 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err
13731374
}
13741375

13751376
repo := &Repository{
1376-
OwnerID: u.ID,
1377-
Owner: u,
1378-
Name: opts.Name,
1379-
LowerName: strings.ToLower(opts.Name),
1380-
Description: opts.Description,
1381-
IsPrivate: opts.IsPrivate,
1382-
IsFsckEnabled: !opts.IsMirror,
1377+
OwnerID: u.ID,
1378+
Owner: u,
1379+
Name: opts.Name,
1380+
LowerName: strings.ToLower(opts.Name),
1381+
Description: opts.Description,
1382+
IsPrivate: opts.IsPrivate,
1383+
IsFsckEnabled: !opts.IsMirror,
1384+
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
13831385
}
13841386

13851387
sess := x.NewSession()

models/repo_branch.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,46 @@ import (
1414
"github.com/Unknwon/com"
1515
)
1616

17+
// discardLocalRepoBranchChanges discards local commits/changes of
18+
// given branch to make sure it is even to remote branch.
19+
func discardLocalRepoBranchChanges(localPath, branch string) error {
20+
if !com.IsExist(localPath) {
21+
return nil
22+
}
23+
// No need to check if nothing in the repository.
24+
if !git.IsBranchExist(localPath, branch) {
25+
return nil
26+
}
27+
28+
refName := "origin/" + branch
29+
if err := git.ResetHEAD(localPath, true, refName); err != nil {
30+
return fmt.Errorf("git reset --hard %s: %v", refName, err)
31+
}
32+
return nil
33+
}
34+
35+
// DiscardLocalRepoBranchChanges discards the local repository branch changes
36+
func (repo *Repository) DiscardLocalRepoBranchChanges(branch string) error {
37+
return discardLocalRepoBranchChanges(repo.LocalCopyPath(), branch)
38+
}
39+
40+
// checkoutNewBranch checks out to a new branch from the a branch name.
41+
func checkoutNewBranch(repoPath, localPath, oldBranch, newBranch string) error {
42+
if err := git.Checkout(localPath, git.CheckoutOptions{
43+
Timeout: time.Duration(setting.Git.Timeout.Pull) * time.Second,
44+
Branch: newBranch,
45+
OldBranch: oldBranch,
46+
}); err != nil {
47+
return fmt.Errorf("git checkout -b %s %s: %v", newBranch, oldBranch, err)
48+
}
49+
return nil
50+
}
51+
52+
// CheckoutNewBranch checks out a new branch
53+
func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
54+
return checkoutNewBranch(repo.RepoPath(), repo.LocalCopyPath(), oldBranch, newBranch)
55+
}
56+
1757
// Branch holds the branch information
1858
type Branch struct {
1959
Path string

0 commit comments

Comments
 (0)