Skip to content

Commit 4ae06ff

Browse files
committed
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: Fix data-race problems in git module (quick patch) (go-gitea#19934) [skip ci] Updated translations via Crowdin Fix copy/paste of empty lines (go-gitea#19798) Normalize line endings in fomantic build files (go-gitea#19932) Make user profile image show full image on mobile (go-gitea#19840) Custom regexp external issues (go-gitea#17624) Use Golang 1.18 for Gitea 1.17 release (go-gitea#19918) Refactor git module, make Gitea use internal git config (go-gitea#19732) [skip ci] Updated translations via Crowdin
2 parents 203b35e + 88f2e45 commit 4ae06ff

Some content is hidden

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

74 files changed

+664
-338
lines changed

.drone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ steps:
109109
depends_on: [test-frontend]
110110

111111
- name: build-backend-no-gcc
112-
image: golang:1.17 # this step is kept as the lowest version of golang that we support
112+
image: golang:1.18 # this step is kept as the lowest version of golang that we support
113113
pull: always
114114
environment:
115115
GO111MODULE: on

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ fomantic:
704704
cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
705705
cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
706706
cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
707+
$(SED_INPLACE) -e 's/\r//g' $(FOMANTIC_WORK_DIR)/build/semantic.css $(FOMANTIC_WORK_DIR)/build/semantic.js
707708
rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*
708709

709710
.PHONY: webpack

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ or if SQLite support is required:
7373

7474
The `build` target is split into two sub-targets:
7575

76-
- `make backend` which requires [Go 1.17](https://go.dev/dl/) or greater.
76+
- `make backend` which requires [Go Stable](https://go.dev/dl/), required version is defined in [go.mod](/go.mod).
7777
- `make frontend` which requires [Node.js LTS](https://nodejs.org/en/download/) or greater and Internet connectivity to download npm dependencies.
7878

7979
When building from the official source tarballs which include pre-built frontend files, the `frontend` target will not be triggered, making it possible to build without Node.js and Internet connectivity.

cmd/serv.go

+37-23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package cmd
77

88
import (
9+
"context"
910
"fmt"
1011
"net/http"
1112
"net/url"
@@ -65,6 +66,21 @@ func setup(logPath string, debug bool) {
6566
if debug {
6667
setting.RunMode = "dev"
6768
}
69+
70+
// Check if setting.RepoRootPath exists. It could be the case that it doesn't exist, this can happen when
71+
// `[repository]` `ROOT` is a relative path and $GITEA_WORK_DIR isn't passed to the SSH connection.
72+
if _, err := os.Stat(setting.RepoRootPath); err != nil {
73+
if os.IsNotExist(err) {
74+
_ = fail("Incorrect configuration, no repository directory.", "Directory `[repository].ROOT` %q was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository].ROOT` an absolute value.", setting.RepoRootPath)
75+
} else {
76+
_ = fail("Incorrect configuration, repository directory is inaccessible", "Directory `[repository].ROOT` %q is inaccessible. err: %v", setting.RepoRootPath, err)
77+
}
78+
return
79+
}
80+
81+
if err := git.InitSimple(context.Background()); err != nil {
82+
_ = fail("Failed to init git", "Failed to init git, err: %v", err)
83+
}
6884
}
6985

7086
var (
@@ -80,12 +96,12 @@ var (
8096
func fail(userMessage, logMessage string, args ...interface{}) error {
8197
// There appears to be a chance to cause a zombie process and failure to read the Exit status
8298
// if nothing is outputted on stdout.
83-
fmt.Fprintln(os.Stdout, "")
84-
fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
99+
_, _ = fmt.Fprintln(os.Stdout, "")
100+
_, _ = fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
85101

86102
if len(logMessage) > 0 {
87103
if !setting.IsProd {
88-
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
104+
_, _ = fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
89105
}
90106
}
91107
ctx, cancel := installSignals()
@@ -237,17 +253,6 @@ func runServ(c *cli.Context) error {
237253
}
238254
return fail("Internal Server Error", "%s", err.Error())
239255
}
240-
os.Setenv(repo_module.EnvRepoIsWiki, strconv.FormatBool(results.IsWiki))
241-
os.Setenv(repo_module.EnvRepoName, results.RepoName)
242-
os.Setenv(repo_module.EnvRepoUsername, results.OwnerName)
243-
os.Setenv(repo_module.EnvPusherName, results.UserName)
244-
os.Setenv(repo_module.EnvPusherEmail, results.UserEmail)
245-
os.Setenv(repo_module.EnvPusherID, strconv.FormatInt(results.UserID, 10))
246-
os.Setenv(repo_module.EnvRepoID, strconv.FormatInt(results.RepoID, 10))
247-
os.Setenv(repo_module.EnvPRID, fmt.Sprintf("%d", 0))
248-
os.Setenv(repo_module.EnvDeployKeyID, fmt.Sprintf("%d", results.DeployKeyID))
249-
os.Setenv(repo_module.EnvKeyID, fmt.Sprintf("%d", results.KeyID))
250-
os.Setenv(repo_module.EnvAppURL, setting.AppURL)
251256

252257
// LFS token authentication
253258
if verb == lfsAuthenticateVerb {
@@ -298,20 +303,29 @@ func runServ(c *cli.Context) error {
298303
gitcmd = exec.CommandContext(ctx, verb, repoPath)
299304
}
300305

301-
// Check if setting.RepoRootPath exists. It could be the case that it doesn't exist, this can happen when
302-
// `[repository]` `ROOT` is a relative path and $GITEA_WORK_DIR isn't passed to the SSH connection.
303-
if _, err := os.Stat(setting.RepoRootPath); err != nil {
304-
if os.IsNotExist(err) {
305-
return fail("Incorrect configuration.",
306-
"Directory `[repository]` `ROOT` %s was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` an absolute value.", setting.RepoRootPath)
307-
}
308-
}
309-
310306
process.SetSysProcAttribute(gitcmd)
311307
gitcmd.Dir = setting.RepoRootPath
312308
gitcmd.Stdout = os.Stdout
313309
gitcmd.Stdin = os.Stdin
314310
gitcmd.Stderr = os.Stderr
311+
gitcmd.Env = append(gitcmd.Env, os.Environ()...)
312+
gitcmd.Env = append(gitcmd.Env,
313+
repo_module.EnvRepoIsWiki+"="+strconv.FormatBool(results.IsWiki),
314+
repo_module.EnvRepoName+"="+results.RepoName,
315+
repo_module.EnvRepoUsername+"="+results.OwnerName,
316+
repo_module.EnvPusherName+"="+results.UserName,
317+
repo_module.EnvPusherEmail+"="+results.UserEmail,
318+
repo_module.EnvPusherID+"="+strconv.FormatInt(results.UserID, 10),
319+
repo_module.EnvRepoID+"="+strconv.FormatInt(results.RepoID, 10),
320+
repo_module.EnvPRID+"="+fmt.Sprintf("%d", 0),
321+
repo_module.EnvDeployKeyID+"="+fmt.Sprintf("%d", results.DeployKeyID),
322+
repo_module.EnvKeyID+"="+fmt.Sprintf("%d", results.KeyID),
323+
repo_module.EnvAppURL+"="+setting.AppURL,
324+
)
325+
// to avoid breaking, here only use the minimal environment variables for the "gitea serv" command.
326+
// it could be re-considered whether to use the same git.CommonGitCmdEnvs() as "git" command later.
327+
gitcmd.Env = append(gitcmd.Env, git.CommonCmdServEnvs()...)
328+
315329
if err = gitcmd.Run(); err != nil {
316330
return fail("Internal error", "Failed to execute git command: %v", err)
317331
}

docs/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ params:
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
2121
version: 1.16.8
22-
minGoVersion: 1.17
22+
minGoVersion: 1.18
2323
goVersion: 1.18
2424
minNodeVersion: 14
2525

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ The following configuration set `Content-Type: application/vnd.android.package-a
315315
- `SSL_MAX_VERSION`: **\<empty\>**: Set the maximum version of ssl support.
316316
- `SSL_CURVE_PREFERENCES`: **X25519,P256**: Set the preferred curves,
317317
- `SSL_CIPHER_SUITES`: **ecdhe_ecdsa_with_aes_256_gcm_sha384,ecdhe_rsa_with_aes_256_gcm_sha384,ecdhe_ecdsa_with_aes_128_gcm_sha256,ecdhe_rsa_with_aes_128_gcm_sha256,ecdhe_ecdsa_with_chacha20_poly1305,ecdhe_rsa_with_chacha20_poly1305**: Set the preferred cipher suites.
318-
- If there is not hardware support for AES suites by default the cha cha suites will be preferred over the AES suites
319-
- supported suites as of go 1.17 are:
318+
- If there is no hardware support for AES suites, by default the ChaCha suites will be preferred over the AES suites.
319+
- supported suites as of Go 1.18 are:
320320
- TLS 1.0 - 1.2 cipher suites
321321
- "rsa_with_rc4_128_sha"
322322
- "rsa_with_3des_ede_cbc_sha"

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module code.gitea.io/gitea
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b

integrations/integration_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
274274
deferFn := PrintCurrentTest(t, ourSkip)
275275
assert.NoError(t, unittest.LoadFixtures())
276276
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
277-
278277
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
278+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
279279
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
280280
if err != nil {
281281
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)
@@ -576,6 +576,7 @@ func resetFixtures(t *testing.T) {
576576
assert.NoError(t, unittest.LoadFixtures())
577577
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
578578
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
579+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
579580
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
580581
if err != nil {
581582
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)

integrations/migration-test/migration_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func initMigrationTest(t *testing.T) func() {
6262
assert.True(t, len(setting.RepoRootPath) != 0)
6363
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
6464
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
65+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
6566
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
6667
if err != nil {
6768
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)

models/migrations/migrations_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ func prepareTestEnv(t *testing.T, skip int, syncModels ...interface{}) (*xorm.En
202202
ourSkip += skip
203203
deferFn := PrintCurrentTest(t, ourSkip)
204204
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
205-
206-
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"),
207-
setting.RepoRootPath))
205+
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
206+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
208207
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
209208
if err != nil {
210209
assert.NoError(t, err, "unable to read the new repo root: %v\n", err)

models/repo/repo.go

+3
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ func (repo *Repository) ComposeMetas() map[string]string {
414414
switch unit.ExternalTrackerConfig().ExternalTrackerStyle {
415415
case markup.IssueNameStyleAlphanumeric:
416416
metas["style"] = markup.IssueNameStyleAlphanumeric
417+
case markup.IssueNameStyleRegexp:
418+
metas["style"] = markup.IssueNameStyleRegexp
419+
metas["regexp"] = unit.ExternalTrackerConfig().ExternalTrackerRegexpPattern
417420
default:
418421
metas["style"] = markup.IssueNameStyleNumeric
419422
}

models/repo/repo_unit.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ func (cfg *ExternalWikiConfig) ToDB() ([]byte, error) {
7676

7777
// ExternalTrackerConfig describes external tracker config
7878
type ExternalTrackerConfig struct {
79-
ExternalTrackerURL string
80-
ExternalTrackerFormat string
81-
ExternalTrackerStyle string
79+
ExternalTrackerURL string
80+
ExternalTrackerFormat string
81+
ExternalTrackerStyle string
82+
ExternalTrackerRegexpPattern string
8283
}
8384

8485
// FromDB fills up a ExternalTrackerConfig from serialized format.

models/repo_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ func TestMetas(t *testing.T) {
7474
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric
7575
testSuccess(markup.IssueNameStyleNumeric)
7676

77+
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleRegexp
78+
testSuccess(markup.IssueNameStyleRegexp)
79+
7780
repo, err := repo_model.GetRepositoryByID(3)
7881
assert.NoError(t, err)
7982

models/unittest/testdb.go

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"code.gitea.io/gitea/models/db"
1616
"code.gitea.io/gitea/modules/base"
17+
"code.gitea.io/gitea/modules/git"
1718
"code.gitea.io/gitea/modules/setting"
1819
"code.gitea.io/gitea/modules/storage"
1920
"code.gitea.io/gitea/modules/util"
@@ -116,6 +117,9 @@ func MainTest(m *testing.M, testOpts *TestOptions) {
116117
if err = CopyDir(filepath.Join(testOpts.GiteaRootPath, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
117118
fatalTestError("util.CopyDir: %v\n", err)
118119
}
120+
if err = git.InitOnceWithSync(context.Background()); err != nil {
121+
fatalTestError("git.Init: %v\n", err)
122+
}
119123

120124
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
121125
if err != nil {
@@ -198,6 +202,7 @@ func PrepareTestEnv(t testing.TB) {
198202
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
199203
metaPath := filepath.Join(giteaRoot, "integrations", "gitea-repositories-meta")
200204
assert.NoError(t, CopyDir(metaPath, setting.RepoRootPath))
205+
assert.NoError(t, git.InitOnceWithSync(context.Background()))
201206

202207
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
203208
assert.NoError(t, err)

modules/git/command.go

+31-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package git
88
import (
99
"bytes"
1010
"context"
11+
"errors"
1112
"fmt"
1213
"io"
1314
"os"
@@ -104,6 +105,25 @@ type RunOpts struct {
104105
PipelineFunc func(context.Context, context.CancelFunc) error
105106
}
106107

108+
// CommonGitCmdEnvs returns the common environment variables for a "git" command.
109+
func CommonGitCmdEnvs() []string {
110+
// at the moment, do not set "GIT_CONFIG_NOSYSTEM", users may have put some configs like "receive.certNonceSeed" in it
111+
return []string{
112+
fmt.Sprintf("LC_ALL=%s", DefaultLocale),
113+
"GIT_TERMINAL_PROMPT=0", // avoid prompting for credentials interactively, supported since git v2.3
114+
"GIT_NO_REPLACE_OBJECTS=1", // ignore replace references (https://git-scm.com/docs/git-replace)
115+
"HOME=" + HomeDir(), // make Gitea use internal git config only, to prevent conflicts with user's git config
116+
}
117+
}
118+
119+
// CommonCmdServEnvs is like CommonGitCmdEnvs but it only returns minimal required environment variables for the "gitea serv" command
120+
func CommonCmdServEnvs() []string {
121+
return []string{
122+
"GIT_NO_REPLACE_OBJECTS=1", // ignore replace references (https://git-scm.com/docs/git-replace)
123+
"HOME=" + HomeDir(), // make Gitea use internal git config only, to prevent conflicts with user's git config
124+
}
125+
}
126+
107127
// Run runs the command with the RunOpts
108128
func (c *Command) Run(opts *RunOpts) error {
109129
if opts == nil {
@@ -148,16 +168,8 @@ func (c *Command) Run(opts *RunOpts) error {
148168
cmd.Env = opts.Env
149169
}
150170

151-
cmd.Env = append(
152-
cmd.Env,
153-
fmt.Sprintf("LC_ALL=%s", DefaultLocale),
154-
// avoid prompting for credentials interactively, supported since git v2.3
155-
"GIT_TERMINAL_PROMPT=0",
156-
// ignore replace references (https://git-scm.com/docs/git-replace)
157-
"GIT_NO_REPLACE_OBJECTS=1",
158-
)
159-
160171
process.SetSysProcAttribute(cmd)
172+
cmd.Env = append(cmd.Env, CommonGitCmdEnvs()...)
161173
cmd.Dir = opts.Dir
162174
cmd.Stdout = opts.Stdout
163175
cmd.Stderr = opts.Stderr
@@ -184,7 +196,9 @@ func (c *Command) Run(opts *RunOpts) error {
184196

185197
type RunStdError interface {
186198
error
199+
Unwrap() error
187200
Stderr() string
201+
IsExitCode(code int) bool
188202
}
189203

190204
type runStdError struct {
@@ -209,6 +223,14 @@ func (r *runStdError) Stderr() string {
209223
return r.stderr
210224
}
211225

226+
func (r *runStdError) IsExitCode(code int) bool {
227+
var exitError *exec.ExitError
228+
if errors.As(r.err, &exitError) {
229+
return exitError.ExitCode() == code
230+
}
231+
return false
232+
}
233+
212234
func bytesToString(b []byte) string {
213235
return *(*string)(unsafe.Pointer(&b)) // that's what Golang's strings.Builder.String() does (go/src/strings/builder.go)
214236
}

modules/git/commit.go

-5
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,6 @@ func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
398398

399399
// GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
400400
func (c *Commit) GetBranchName() (string, error) {
401-
err := LoadGitVersion()
402-
if err != nil {
403-
return "", fmt.Errorf("Git version missing: %v", err)
404-
}
405-
406401
args := []string{
407402
"name-rev",
408403
}

0 commit comments

Comments
 (0)