Skip to content

Commit 6f15516

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Fix dropdown menu header and mobile view (go-gitea#33108) workflow_dispatch use workflow from trigger branch (go-gitea#33098) [skip ci] Updated translations via Crowdin Trivial fixes (go-gitea#33103) Fix empty git repo handling logic (go-gitea#33101) Refactor legacy line-number and scroll code (go-gitea#33094) Use `Project-URL` metadata field to get a PyPI package's homepage URL (go-gitea#33089) Clean up legacy form CSS styles (go-gitea#33081) [skip ci] Updated translations via Crowdin add myself to maintainers (go-gitea#33088) Make Gitea always use its internal config, ignore `/etc/gitconfig` (go-gitea#33076) Fix "stop time tracking button" on navbar (go-gitea#33084) Fix bleve fuzziness search (go-gitea#33078) Try to fix ACME directory problem (go-gitea#33072) Refactor env var related code (go-gitea#33075)
2 parents 9754baf + 3c1c508 commit 6f15516

Some content is hidden

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

71 files changed

+817
-1126
lines changed

MAINTAINERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Gary Kim <[email protected]> (@gary-kim)
3131
Guillermo Prandi <[email protected]> (@guillep2k)
3232
Mura Li <[email protected]> (@typeless)
3333
6543 <[email protected]> (@6543)
34-
jaqra <[email protected]> (@jaqra)
3534
David Svantesson <[email protected]> (@davidsvantesson)
3635
a1012112796 <[email protected]> (@a1012112796)
3736
Karl Heinz Marbaise <[email protected]> (@khmarbaise)
@@ -63,3 +62,4 @@ Yu Liu <[email protected]> (@HEREYUA)
6362
Kemal Zebari <[email protected]> (@kemzeb)
6463
Rowan Bohde <[email protected]> (@bohde)
6564
hiifong <[email protected]> (@hiifong)
65+
metiftikci <[email protected]> (@metiftikci)

cmd/main_test.go

+10-31
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package cmd
66
import (
77
"fmt"
88
"io"
9-
"os"
109
"path/filepath"
1110
"strings"
1211
"testing"
@@ -113,37 +112,17 @@ func TestCliCmd(t *testing.T) {
113112
_, _ = fmt.Fprint(ctx.App.Writer, makePathOutput(setting.AppWorkPath, setting.CustomPath, setting.CustomConf))
114113
return nil
115114
})
116-
var envBackup []string
117-
for _, s := range os.Environ() {
118-
if strings.HasPrefix(s, "GITEA_") && strings.Contains(s, "=") {
119-
envBackup = append(envBackup, s)
120-
}
121-
}
122-
clearGiteaEnv := func() {
123-
for _, s := range os.Environ() {
124-
if strings.HasPrefix(s, "GITEA_") {
125-
_ = os.Unsetenv(s)
126-
}
127-
}
128-
}
129-
defer func() {
130-
clearGiteaEnv()
131-
for _, s := range envBackup {
132-
k, v, _ := strings.Cut(s, "=")
133-
_ = os.Setenv(k, v)
134-
}
135-
}()
136-
137115
for _, c := range cases {
138-
clearGiteaEnv()
139-
for k, v := range c.env {
140-
_ = os.Setenv(k, v)
141-
}
142-
args := strings.Split(c.cmd, " ") // for test only, "split" is good enough
143-
r, err := runTestApp(app, args...)
144-
assert.NoError(t, err, c.cmd)
145-
assert.NotEmpty(t, c.exp, c.cmd)
146-
assert.Contains(t, r.Stdout, c.exp, c.cmd)
116+
t.Run(c.cmd, func(t *testing.T) {
117+
for k, v := range c.env {
118+
t.Setenv(k, v)
119+
}
120+
args := strings.Split(c.cmd, " ") // for test only, "split" is good enough
121+
r, err := runTestApp(app, args...)
122+
assert.NoError(t, err, c.cmd)
123+
assert.NotEmpty(t, c.exp, c.cmd)
124+
assert.Contains(t, r.Stdout, c.exp, c.cmd)
125+
})
147126
}
148127
}
149128

cmd/migrate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
var CmdMigrate = &cli.Command{
1919
Name: "migrate",
2020
Usage: "Migrate the database",
21-
Description: "This is a command for migrating the database, so that you can run gitea admin create-user before starting the server.",
21+
Description: `This is a command for migrating the database, so that you can run "gitea admin create user" before starting the server.`,
2222
Action: runMigrate,
2323
}
2424

cmd/web_acme.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func runACME(listenAddr string, m http.Handler) error {
5454
altTLSALPNPort = p
5555
}
5656

57-
magic := certmagic.NewDefault()
57+
magic := &certmagic.Default
5858
magic.Storage = &certmagic.FileStorage{Path: setting.AcmeLiveDirectory}
5959
// Try to use private CA root if provided, otherwise defaults to system's trust
6060
var certPool *x509.CertPool

custom/conf/app.example.ini

+4
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,10 @@ LEVEL = Info
14851485
;REPO_INDEXER_EXCLUDE =
14861486
;;
14871487
;MAX_FILE_SIZE = 1048576
1488+
;;
1489+
;; Bleve engine has performance problems with fuzzy search, so we limit the fuzziness to 0 by default to disable it.
1490+
;; If you'd like to enable it, you can set it to a value between 0 and 2.
1491+
;TYPE_BLEVE_MAX_FUZZINESS = 0
14881492

14891493
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14901494
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ require (
7171
github.com/google/uuid v1.6.0
7272
github.com/gorilla/feeds v1.2.0
7373
github.com/gorilla/sessions v1.4.0
74-
github.com/h2non/gock v1.2.0
7574
github.com/hashicorp/go-version v1.7.0
7675
github.com/hashicorp/golang-lru/v2 v2.0.7
7776
github.com/huandu/xstrings v1.5.0
@@ -230,7 +229,6 @@ require (
230229
github.com/gorilla/handlers v1.5.2 // indirect
231230
github.com/gorilla/mux v1.8.1 // indirect
232231
github.com/gorilla/securecookie v1.1.2 // indirect
233-
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
234232
github.com/hashicorp/errwrap v1.1.0 // indirect
235233
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
236234
github.com/hashicorp/go-multierror v1.1.1 // indirect

go.sum

-6
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,6 @@ github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/z
452452
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
453453
github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ=
454454
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
455-
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
456-
github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk=
457-
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
458-
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
459455
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
460456
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
461457
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@@ -599,8 +595,6 @@ github.com/msteinert/pam v1.2.0 h1:mYfjlvN2KYs2Pb9G6nb/1f/nPfAttT/Jee5Sq9r3bGE=
599595
github.com/msteinert/pam v1.2.0/go.mod h1:d2n0DCUK8rGecChV3JzvmsDjOY4R7AYbsNxAT+ftQl0=
600596
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
601597
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
602-
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
603-
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
604598
github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek=
605599
github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o=
606600
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=

models/repo/repo.go

+2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ func (repo *Repository) IsBroken() bool {
279279
}
280280

281281
// MarkAsBrokenEmpty marks the repo as broken and empty
282+
// FIXME: the status "broken" and "is_empty" were abused,
283+
// The code always set them together, no way to distinguish whether a repo is really "empty" or "broken"
282284
func (repo *Repository) MarkAsBrokenEmpty() {
283285
repo.Status = RepositoryBroken
284286
repo.IsEmpty = true

models/unittest/testdb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func InitSettings() {
5959
_ = hash.Register("dummy", hash.NewDummyHasher)
6060

6161
setting.PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy")
62-
setting.InitGiteaEnvVars()
62+
setting.InitGiteaEnvVarsForTesting()
6363
}
6464

6565
// TestOptions represents test options

modules/auth/password/pwn/pwn_test.go

+22-11
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,57 @@
44
package pwn
55

66
import (
7+
"errors"
8+
"io"
79
"net/http"
10+
"strings"
811
"testing"
9-
"time"
1012

11-
"github.com/h2non/gock"
1213
"github.com/stretchr/testify/assert"
1314
)
1415

15-
var client = New(WithHTTP(&http.Client{
16-
Timeout: time.Second * 2,
17-
}))
16+
type mockTransport struct{}
17+
18+
func (mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
19+
if req.URL.Host != "api.pwnedpasswords.com" {
20+
return nil, errors.New("unsupported host")
21+
}
22+
respMap := map[string]string{
23+
"/range/5c1d8": "EAF2F254732680E8AC339B84F3266ECCBB5:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2",
24+
"/range/ba189": "FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4",
25+
"/range/a1733": "C4CE0F1F0062B27B9E2F41AF0C08218017C:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2\r\nFE81480327C992FE62065A827429DD1318B:0",
26+
"/range/5617b": "FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0",
27+
"/range/79082": "FDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0\r\nAFEF386F56EB0B4BE314E07696E5E6E6536:0",
28+
}
29+
if resp, ok := respMap[req.URL.Path]; ok {
30+
return &http.Response{Request: req, Body: io.NopCloser(strings.NewReader(resp))}, nil
31+
}
32+
return nil, errors.New("unsupported path")
33+
}
1834

1935
func TestPassword(t *testing.T) {
20-
defer gock.Off()
36+
client := New(WithHTTP(&http.Client{Transport: mockTransport{}}))
2137

2238
count, err := client.CheckPassword("", false)
2339
assert.ErrorIs(t, err, ErrEmptyPassword, "blank input should return ErrEmptyPassword")
2440
assert.Equal(t, -1, count)
2541

26-
gock.New("https://api.pwnedpasswords.com").Get("/range/5c1d8").Times(1).Reply(200).BodyString("EAF2F254732680E8AC339B84F3266ECCBB5:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2")
2742
count, err = client.CheckPassword("pwned", false)
2843
assert.NoError(t, err)
2944
assert.Equal(t, 1, count)
3045

31-
gock.New("https://api.pwnedpasswords.com").Get("/range/ba189").Times(1).Reply(200).BodyString("FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4")
3246
count, err = client.CheckPassword("notpwned", false)
3347
assert.NoError(t, err)
3448
assert.Equal(t, 0, count)
3549

36-
gock.New("https://api.pwnedpasswords.com").Get("/range/a1733").Times(1).Reply(200).BodyString("C4CE0F1F0062B27B9E2F41AF0C08218017C:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2\r\nFE81480327C992FE62065A827429DD1318B:0")
3750
count, err = client.CheckPassword("paddedpwned", true)
3851
assert.NoError(t, err)
3952
assert.Equal(t, 1, count)
4053

41-
gock.New("https://api.pwnedpasswords.com").Get("/range/5617b").Times(1).Reply(200).BodyString("FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0")
4254
count, err = client.CheckPassword("paddednotpwned", true)
4355
assert.NoError(t, err)
4456
assert.Equal(t, 0, count)
4557

46-
gock.New("https://api.pwnedpasswords.com").Get("/range/79082").Times(1).Reply(200).BodyString("FDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0\r\nAFEF386F56EB0B4BE314E07696E5E6E6536:0")
4758
count, err = client.CheckPassword("paddednotpwnedzero", true)
4859
assert.NoError(t, err)
4960
assert.Equal(t, 0, count)

modules/git/command.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,16 @@ type RunOpts struct {
236236
}
237237

238238
func commonBaseEnvs() []string {
239-
// at the moment, do not set "GIT_CONFIG_NOSYSTEM", users may have put some configs like "receive.certNonceSeed" in it
240239
envs := []string{
241-
"HOME=" + HomeDir(), // make Gitea use internal git config only, to prevent conflicts with user's git config
242-
"GIT_NO_REPLACE_OBJECTS=1", // ignore replace references (https://git-scm.com/docs/git-replace)
240+
// Make Gitea use internal git config only, to prevent conflicts with user's git config
241+
// It's better to use GIT_CONFIG_GLOBAL, but it requires git >= 2.32, so we still use HOME at the moment.
242+
"HOME=" + HomeDir(),
243+
// Avoid using system git config, it would cause problems (eg: use macOS osxkeychain to show a modal dialog, auto installing lfs hooks)
244+
// This might be a breaking change in 1.24, because some users said that they have put some configs like "receive.certNonceSeed" in "/etc/gitconfig"
245+
// For these users, they need to migrate the necessary configs to Gitea's git config file manually.
246+
"GIT_CONFIG_NOSYSTEM=1",
247+
// Ignore replace references (https://git-scm.com/docs/git-replace)
248+
"GIT_NO_REPLACE_OBJECTS=1",
243249
}
244250

245251
// some environment variables should be passed to git command

modules/git/repo_archive.go

-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"fmt"
1010
"io"
11-
"os"
1211
"path/filepath"
1312
"strings"
1413
)
@@ -63,15 +62,11 @@ func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, t
6362
cmd.AddOptionFormat("--format=%s", format.String())
6463
cmd.AddDynamicArguments(commitID)
6564

66-
// Avoid LFS hooks getting installed because of /etc/gitconfig, which can break pull requests.
67-
env := append(os.Environ(), "GIT_CONFIG_NOSYSTEM=1")
68-
6965
var stderr strings.Builder
7066
err := cmd.Run(&RunOpts{
7167
Dir: repo.Path,
7268
Stdout: target,
7369
Stderr: &stderr,
74-
Env: env,
7570
})
7671
if err != nil {
7772
return ConcatenateError(err, stderr.String())

modules/indexer/code/indexer.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,12 @@ func Init() {
123123
for _, indexerData := range items {
124124
log.Trace("IndexerData Process Repo: %d", indexerData.RepoID)
125125
if err := index(ctx, indexer, indexerData.RepoID); err != nil {
126-
unhandled = append(unhandled, indexerData)
127126
if !setting.IsInTesting {
128127
log.Error("Codes indexer handler: index error for repo %v: %v", indexerData.RepoID, err)
129128
}
130129
}
131130
}
132-
return unhandled
131+
return nil // do not re-queue the failed items, otherwise some broken repo will block the queue
133132
}
134133

135134
indexerQueue = queue.CreateUniqueQueue(ctx, "code_indexer", handler)

modules/indexer/code/indexer_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"code.gitea.io/gitea/modules/indexer/code/bleve"
1616
"code.gitea.io/gitea/modules/indexer/code/elasticsearch"
1717
"code.gitea.io/gitea/modules/indexer/code/internal"
18+
"code.gitea.io/gitea/modules/setting"
19+
"code.gitea.io/gitea/modules/test"
1820

1921
_ "code.gitea.io/gitea/models"
2022
_ "code.gitea.io/gitea/models/actions"
@@ -279,7 +281,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
279281

280282
func TestBleveIndexAndSearch(t *testing.T) {
281283
unittest.PrepareTestEnv(t)
282-
284+
defer test.MockVariableValue(&setting.Indexer.TypeBleveMaxFuzzniess, 2)()
283285
dir := t.TempDir()
284286

285287
idx := bleve.NewIndexer(dir)

modules/indexer/internal/bleve/util.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"unicode"
1010

1111
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/setting"
1213
"code.gitea.io/gitea/modules/util"
1314

1415
"github.com/blevesearch/bleve/v2"
@@ -54,9 +55,9 @@ func openIndexer(path string, latestVersion int) (bleve.Index, int, error) {
5455
return index, 0, nil
5556
}
5657

57-
// This method test the GuessFuzzinessByKeyword method. The fuzziness is based on the levenshtein distance and determines how many chars
58-
// may be different on two string and they still be considered equivalent.
59-
// Given a phrasse, its shortest word determines its fuzziness. If a phrase uses CJK (eg: `갃갃갃` `啊啊啊`), the fuzziness is zero.
58+
// GuessFuzzinessByKeyword guesses fuzziness based on the levenshtein distance and determines how many chars
59+
// may be different on two string, and they still be considered equivalent.
60+
// Given a phrase, its shortest word determines its fuzziness. If a phrase uses CJK (eg: `갃갃갃` `啊啊啊`), the fuzziness is zero.
6061
func GuessFuzzinessByKeyword(s string) int {
6162
tokenizer := unicode_tokenizer.NewUnicodeTokenizer()
6263
tokens := tokenizer.Tokenize([]byte(s))
@@ -85,5 +86,5 @@ func guessFuzzinessByKeyword(s string) int {
8586
return 0
8687
}
8788
}
88-
return min(maxFuzziness, len(s)/4)
89+
return min(min(setting.Indexer.TypeBleveMaxFuzzniess, maxFuzziness), len(s)/4)
8990
}

modules/indexer/internal/bleve/util_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ import (
77
"fmt"
88
"testing"
99

10+
"code.gitea.io/gitea/modules/setting"
11+
"code.gitea.io/gitea/modules/test"
12+
1013
"github.com/stretchr/testify/assert"
1114
)
1215

1316
func TestBleveGuessFuzzinessByKeyword(t *testing.T) {
17+
defer test.MockVariableValue(&setting.Indexer.TypeBleveMaxFuzzniess, 2)()
18+
1419
scenarios := []struct {
1520
Input string
1621
Fuzziness int // See util.go for the definition of fuzziness in this particular context
@@ -46,7 +51,7 @@ func TestBleveGuessFuzzinessByKeyword(t *testing.T) {
4651
}
4752

4853
for _, scenario := range scenarios {
49-
t.Run(fmt.Sprintf("ensure fuzziness of '%s' is '%d'", scenario.Input, scenario.Fuzziness), func(t *testing.T) {
54+
t.Run(fmt.Sprintf("Fuziniess:%s=%d", scenario.Input, scenario.Fuzziness), func(t *testing.T) {
5055
assert.Equal(t, scenario.Fuzziness, GuessFuzzinessByKeyword(scenario.Input))
5156
})
5257
}

modules/markup/sanitizer_default.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
4848
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^(unchecked|checked|indeterminate)$`)).OnElements("li")
4949

5050
// Allow 'color' and 'background-color' properties for the style attribute on text elements.
51-
policy.AllowStyles("color", "background-color").OnElements("span", "p")
51+
policy.AllowStyles("color", "background-color").OnElements("div", "span", "p", "tr", "th", "td")
5252

5353
policy.AllowAttrs("src", "autoplay", "controls").OnElements("video")
5454

modules/setting/config_env.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,24 @@ func EnvironmentToConfig(cfg ConfigProvider, envs []string) (changed bool) {
167167
return changed
168168
}
169169

170-
// InitGiteaEnvVars initilises the environment for gitea
170+
// InitGiteaEnvVars initializes the environment variables for gitea
171171
func InitGiteaEnvVars() {
172-
_ = os.Unsetenv("XDG_CONFIG_HOME") // unset if set as HOME is managed by gitea
172+
// Ideally Gitea should only accept the environment variables which it clearly knows instead of unsetting the ones it doesn't want,
173+
// but the ideal behavior would be a breaking change, and it seems not bringing enough benefits to end users,
174+
// so at the moment we could still keep "unsetting the unnecessary environments"
175+
176+
// HOME is managed by Gitea, Gitea's git should use "HOME/.gitconfig".
177+
// But git would try "XDG_CONFIG_HOME/git/config" first if "HOME/.gitconfig" does not exist,
178+
// then our git.InitFull would still write to "XDG_CONFIG_HOME/git/config" if XDG_CONFIG_HOME is set.
179+
_ = os.Unsetenv("XDG_CONFIG_HOME")
180+
}
181+
182+
func InitGiteaEnvVarsForTesting() {
183+
InitGiteaEnvVars()
184+
_ = os.Unsetenv("GIT_AUTHOR_NAME")
185+
_ = os.Unsetenv("GIT_AUTHOR_EMAIL")
186+
_ = os.Unsetenv("GIT_AUTHOR_DATE")
187+
_ = os.Unsetenv("GIT_COMMITTER_NAME")
188+
_ = os.Unsetenv("GIT_COMMITTER_EMAIL")
189+
_ = os.Unsetenv("GIT_COMMITTER_DATE")
173190
}

0 commit comments

Comments
 (0)