Skip to content

Commit e312ff1

Browse files
authored
Merge branch 'main' into feature-migrate-codebase
2 parents 849b89f + 4646c7c commit e312ff1

File tree

539 files changed

+8355
-6264
lines changed

Some content is hidden

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

539 files changed

+8355
-6264
lines changed

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,5 @@ CMD ["/bin/s6-svscan", "/etc/s6"]
6666
COPY docker/root /
6767
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
6868
COPY --from=build-env /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
69-
RUN chmod 755 /usr/bin/entrypoint /app/gitea/gitea /usr/local/bin/environment-to-ini
69+
RUN chmod 755 /usr/bin/entrypoint /app/gitea/gitea /usr/local/bin/gitea /usr/local/bin/environment-to-ini
7070
RUN chmod 755 /etc/s6/gitea/* /etc/s6/openssh/* /etc/s6/.s6-svscan/*
71-
RUN ln -s /app/gitea/gitea /usr/local/bin/gitea

Dockerfile.rootless

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ RUN mkdir -p /var/lib/gitea /etc/gitea
5353
RUN chown git:git /var/lib/gitea /etc/gitea
5454

5555
COPY docker/rootless /
56-
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea
56+
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
5757
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
58-
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-setup.sh /usr/local/bin/gitea /usr/local/bin/environment-to-ini
58+
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-setup.sh /app/gitea/gitea /usr/local/bin/gitea /usr/local/bin/environment-to-ini
5959

6060
#git:git
6161
USER 1000:1000

build/code-batch-process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ func main() {
267267
logVerbose("batch cmd: %s %v", subCmd, substArgs)
268268
switch subCmd {
269269
case "gitea-fmt":
270-
cmdErrors = append(cmdErrors, passThroughCmd("gofmt", substArgs))
271270
if containsString(subArgs, "-w") {
272271
cmdErrors = append(cmdErrors, giteaFormatGoImports(files))
273272
}
273+
cmdErrors = append(cmdErrors, passThroughCmd("gofmt", substArgs))
274274
case "misspell":
275275
cmdErrors = append(cmdErrors, passThroughCmd("misspell", substArgs))
276276
default:

cmd/admin.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/models"
1717
"code.gitea.io/gitea/models/db"
1818
"code.gitea.io/gitea/models/login"
19+
user_model "code.gitea.io/gitea/models/user"
1920
"code.gitea.io/gitea/modules/git"
2021
"code.gitea.io/gitea/modules/graceful"
2122
"code.gitea.io/gitea/modules/log"
@@ -358,15 +359,15 @@ func runChangePassword(c *cli.Context) error {
358359
return errors.New("The password you chose is on a list of stolen passwords previously exposed in public data breaches. Please try again with a different password.\nFor more details, see https://haveibeenpwned.com/Passwords")
359360
}
360361
uname := c.String("username")
361-
user, err := models.GetUserByName(uname)
362+
user, err := user_model.GetUserByName(uname)
362363
if err != nil {
363364
return err
364365
}
365366
if err = user.SetPassword(c.String("password")); err != nil {
366367
return err
367368
}
368369

369-
if err = models.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
370+
if err = user_model.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
370371
return err
371372
}
372373

@@ -424,15 +425,15 @@ func runCreateUser(c *cli.Context) error {
424425

425426
// If this is the first user being created.
426427
// Take it as the admin and don't force a password update.
427-
if n := models.CountUsers(); n == 0 {
428+
if n := user_model.CountUsers(); n == 0 {
428429
changePassword = false
429430
}
430431

431432
if c.IsSet("must-change-password") {
432433
changePassword = c.Bool("must-change-password")
433434
}
434435

435-
u := &models.User{
436+
u := &user_model.User{
436437
Name: username,
437438
Email: c.String("email"),
438439
Passwd: password,
@@ -442,7 +443,7 @@ func runCreateUser(c *cli.Context) error {
442443
Theme: setting.UI.DefaultTheme,
443444
}
444445

445-
if err := models.CreateUser(u); err != nil {
446+
if err := user_model.CreateUser(u); err != nil {
446447
return fmt.Errorf("CreateUser: %v", err)
447448
}
448449

@@ -471,7 +472,7 @@ func runListUsers(c *cli.Context) error {
471472
return err
472473
}
473474

474-
users, err := models.GetAllUsers()
475+
users, err := user_model.GetAllUsers()
475476

476477
if err != nil {
477478
return err
@@ -516,13 +517,13 @@ func runDeleteUser(c *cli.Context) error {
516517
}
517518

518519
var err error
519-
var user *models.User
520+
var user *user_model.User
520521
if c.IsSet("email") {
521-
user, err = models.GetUserByEmail(c.String("email"))
522+
user, err = user_model.GetUserByEmail(c.String("email"))
522523
} else if c.IsSet("username") {
523-
user, err = models.GetUserByName(c.String("username"))
524+
user, err = user_model.GetUserByName(c.String("username"))
524525
} else {
525-
user, err = models.GetUserByID(c.Int64("id"))
526+
user, err = user_model.GetUserByID(c.Int64("id"))
526527
}
527528
if err != nil {
528529
return err

cmd/cmd.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"syscall"
1717

1818
"code.gitea.io/gitea/models/db"
19+
"code.gitea.io/gitea/modules/log"
1920
"code.gitea.io/gitea/modules/setting"
2021
"code.gitea.io/gitea/modules/util"
2122

@@ -57,15 +58,17 @@ func confirm() (bool, error) {
5758
}
5859

5960
func initDB(ctx context.Context) error {
60-
return initDBDisableConsole(ctx, false)
61-
}
62-
63-
func initDBDisableConsole(ctx context.Context, disableConsole bool) error {
64-
setting.NewContext()
61+
setting.LoadFromExisting()
6562
setting.InitDBConfig()
66-
setting.NewXORMLogService(disableConsole)
63+
setting.NewXORMLogService(false)
64+
65+
if setting.Database.Type == "" {
66+
log.Fatal(`Database settings are missing from the configuration file: %q.
67+
Ensure you are running in the correct environment or set the correct configuration file with -c.
68+
If this is the intended configuration file complete the [database] section.`, setting.CustomConf)
69+
}
6770
if err := db.InitEngine(ctx); err != nil {
68-
return fmt.Errorf("models.SetEngine: %v", err)
71+
return fmt.Errorf("unable to initialise the database using the configuration in %q. Error: %v", setting.CustomConf, err)
6972
}
7073
return nil
7174
}

cmd/convert.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func runConvert(ctx *cli.Context) error {
3535
log.Info("Custom path: %s", setting.CustomPath)
3636
log.Info("Log path: %s", setting.LogRootPath)
3737
log.Info("Configuration file: %s", setting.CustomConf)
38-
setting.InitDBConfig()
3938

4039
if !setting.Database.UseMySQL {
4140
fmt.Println("This command can only be used with a MySQL database")

cmd/doctor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func runRecreateTable(ctx *cli.Context) error {
8787
golog.SetPrefix("")
8888
golog.SetOutput(log.NewLoggerAsWriter("INFO", log.GetLogger(log.DEFAULT)))
8989

90-
setting.NewContext()
90+
setting.LoadFromExisting()
9191
setting.InitDBConfig()
9292

9393
setting.EnableXORMLog = ctx.Bool("debug")

cmd/dump.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ func runDump(ctx *cli.Context) error {
159159
fatal("Deleting default logger failed. Can not write to stdout: %v", err)
160160
}
161161
}
162-
setting.NewContext()
162+
setting.LoadFromExisting()
163+
163164
// make sure we are logging to the console no matter what the configuration tells us do to
164165
if _, err := setting.Cfg.Section("log").NewKey("MODE", "console"); err != nil {
165166
fatal("Setting logging mode to console failed: %v", err)

cmd/dump_repo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func runDumpRepository(ctx *cli.Context) error {
8888
log.Info("Custom path: %s", setting.CustomPath)
8989
log.Info("Log path: %s", setting.LogRootPath)
9090
log.Info("Configuration file: %s", setting.CustomConf)
91-
setting.InitDBConfig()
9291

9392
var (
9493
serviceType structs.GitServiceType

cmd/embedded.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func initEmbeddedExtractor(c *cli.Context) error {
115115
log.DelNamedLogger(log.DEFAULT)
116116

117117
// Read configuration file
118-
setting.NewContext()
118+
setting.LoadAllowEmpty()
119119

120120
pats, err := getPatterns(c.Args())
121121
if err != nil {

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func runHookPostReceive(c *cli.Context) error {
309309
defer cancel()
310310

311311
// First of all run update-server-info no matter what
312-
if _, err := git.NewCommand("update-server-info").SetParentContext(ctx).Run(); err != nil {
312+
if _, err := git.NewCommandContext(ctx, "update-server-info").Run(); err != nil {
313313
return fmt.Errorf("Failed to call 'git update-server-info': %v", err)
314314
}
315315

cmd/mailer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func runSendMail(c *cli.Context) error {
1818
ctx, cancel := installSignals()
1919
defer cancel()
2020

21-
setting.NewContext()
21+
setting.LoadFromExisting()
2222

2323
if err := argsSet(c, "title"); err != nil {
2424
return err

cmd/migrate.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func runMigrate(ctx *cli.Context) error {
3636
log.Info("Custom path: %s", setting.CustomPath)
3737
log.Info("Log path: %s", setting.LogRootPath)
3838
log.Info("Configuration file: %s", setting.CustomConf)
39-
setting.InitDBConfig()
4039

4140
if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
4241
log.Fatal("Failed to initialize ORM engine: %v", err)

cmd/migrate_storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/models/db"
1414
"code.gitea.io/gitea/models/migrations"
1515
repo_model "code.gitea.io/gitea/models/repo"
16+
user_model "code.gitea.io/gitea/models/user"
1617
"code.gitea.io/gitea/modules/log"
1718
"code.gitea.io/gitea/modules/setting"
1819
"code.gitea.io/gitea/modules/storage"
@@ -94,7 +95,7 @@ func migrateLFS(dstStorage storage.ObjectStorage) error {
9495
}
9596

9697
func migrateAvatars(dstStorage storage.ObjectStorage) error {
97-
return models.IterateUser(func(user *models.User) error {
98+
return user_model.IterateUser(func(user *user_model.User) error {
9899
_, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath())
99100
return err
100101
})
@@ -120,7 +121,6 @@ func runMigrateStorage(ctx *cli.Context) error {
120121
log.Info("Custom path: %s", setting.CustomPath)
121122
log.Info("Log path: %s", setting.LogRootPath)
122123
log.Info("Configuration file: %s", setting.CustomConf)
123-
setting.InitDBConfig()
124124

125125
if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
126126
log.Fatal("Failed to initialize ORM engine: %v", err)

cmd/restore_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func runRestoreRepository(c *cli.Context) error {
5050
ctx, cancel := installSignals()
5151
defer cancel()
5252

53-
setting.NewContext()
53+
setting.LoadFromExisting()
5454

5555
statusCode, errStr := private.RestoreRepo(
5656
ctx,

cmd/serv.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"time"
1818

1919
"code.gitea.io/gitea/models"
20+
"code.gitea.io/gitea/models/perm"
2021
"code.gitea.io/gitea/modules/git"
2122
"code.gitea.io/gitea/modules/json"
2223
"code.gitea.io/gitea/modules/log"
@@ -57,18 +58,18 @@ func setup(logPath string, debug bool) {
5758
} else {
5859
_ = log.NewLogger(1000, "console", "console", `{"level":"fatal","stacktracelevel":"NONE","stderr":true}`)
5960
}
60-
setting.NewContext()
61+
setting.LoadFromExisting()
6162
if debug {
6263
setting.RunMode = "dev"
6364
}
6465
}
6566

6667
var (
67-
allowedCommands = map[string]models.AccessMode{
68-
"git-upload-pack": models.AccessModeRead,
69-
"git-upload-archive": models.AccessModeRead,
70-
"git-receive-pack": models.AccessModeWrite,
71-
lfsAuthenticateVerb: models.AccessModeNone,
68+
allowedCommands = map[string]perm.AccessMode{
69+
"git-upload-pack": perm.AccessModeRead,
70+
"git-upload-archive": perm.AccessModeRead,
71+
"git-receive-pack": perm.AccessModeWrite,
72+
lfsAuthenticateVerb: perm.AccessModeNone,
7273
}
7374
alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
7475
)
@@ -214,9 +215,9 @@ func runServ(c *cli.Context) error {
214215

215216
if verb == lfsAuthenticateVerb {
216217
if lfsVerb == "upload" {
217-
requestedMode = models.AccessModeWrite
218+
requestedMode = perm.AccessModeWrite
218219
} else if lfsVerb == "download" {
219-
requestedMode = models.AccessModeRead
220+
requestedMode = perm.AccessModeRead
220221
} else {
221222
return fail("Unknown LFS verb", "Unknown lfs verb %s", lfsVerb)
222223
}

cmd/web.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func runWeb(ctx *cli.Context) error {
124124
}
125125
c := install.Routes()
126126
err := listen(c, false)
127+
if err != nil {
128+
log.Critical("Unable to open listener for installer. Is Gitea already running?")
129+
graceful.GetManager().DoGracefulShutdown()
130+
}
127131
select {
128132
case <-graceful.GetManager().IsShutdown():
129133
<-graceful.GetManager().Done()
@@ -145,7 +149,15 @@ func runWeb(ctx *cli.Context) error {
145149

146150
log.Info("Global init")
147151
// Perform global initialization
148-
routers.GlobalInit(graceful.GetManager().HammerContext())
152+
setting.LoadFromExisting()
153+
routers.GlobalInitInstalled(graceful.GetManager().HammerContext())
154+
155+
// We check that AppDataPath exists here (it should have been created during installation)
156+
// We can't check it in `GlobalInitInstalled`, because some integration tests
157+
// use cmd -> GlobalInitInstalled, but the AppDataPath doesn't exist during those tests.
158+
if _, err := os.Stat(setting.AppDataPath); err != nil {
159+
log.Fatal("Can not find APP_DATA_PATH '%s'", setting.AppDataPath)
160+
}
149161

150162
// Override the provided port number within the configuration
151163
if ctx.IsSet("port") {

contrib/environment-to-ini/environment-to-ini.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func runEnvironmentToIni(c *cli.Context) error {
156156
destination = setting.CustomConf
157157
}
158158
if destination != setting.CustomConf || changed {
159+
log.Info("Settings saved to: %q", destination)
159160
err = cfg.SaveTo(destination)
160161
if err != nil {
161162
return err

contrib/fhs-compliant-script/gitea

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

3-
########################################################################
4-
# This script some defaults for gitea to run in a FHS compliant manner #
5-
########################################################################
3+
#############################################################################
4+
# This script sets some defaults for gitea to run in a FHS compliant manner #
5+
#############################################################################
66

77
# It assumes that you place this script as gitea in /usr/bin
88
#
@@ -36,7 +36,7 @@ if [ -z "$APP_INI_SET" ]; then
3636
CONF_ARG="-c \"$APP_INI\""
3737
fi
3838

39-
# Provide FHS compliant defaults to
40-
exec -a "$0" GITEA_WORK_DIR="${GITEA_WORK_DIR:-$WORK_DIR}" "$GITEA" $CONF_ARG "$@"
39+
# Provide FHS compliant defaults
40+
GITEA_WORK_DIR="${GITEA_WORK_DIR:-$WORK_DIR}" exec -a "$0" "$GITEA" $CONF_ARG "$@"
4141

4242

contrib/pr/checkout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func runPR() {
4949
log.Fatal(err)
5050
}
5151
setting.SetCustomPathAndConf("", "", "")
52-
setting.NewContext()
52+
setting.LoadAllowEmpty()
5353

5454
setting.RepoRootPath, err = os.MkdirTemp(os.TempDir(), "repos")
5555
if err != nil {
@@ -215,7 +215,7 @@ func main() {
215215
//Use git cli command for windows
216216
runCmd("git", "fetch", remoteUpstream, fmt.Sprintf("pull/%s/head:%s", pr, branch))
217217
} else {
218-
ref := fmt.Sprintf("refs/pull/%s/head:%s", pr, branchRef)
218+
ref := fmt.Sprintf("%s%s/head:%s", gitea_git.PullPrefix, pr, branchRef)
219219
err = repo.Fetch(&git.FetchOptions{
220220
RemoteName: remoteUpstream,
221221
RefSpecs: []config.RefSpec{

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,9 @@ PATH =
900900
;;
901901
;; In default merge messages only include approvers who are official
902902
;DEFAULT_MERGE_MESSAGE_OFFICIAL_APPROVERS_ONLY = true
903+
;;
904+
;; Add co-authored-by and co-committed-by trailers if committer does not match author
905+
;ADD_CO_COMMITTER_TRAILERS = true
903906

904907
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
905908
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docker/root/etc/s6/gitea/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
[[ -f ./setup ]] && source ./setup
33

44
pushd /app/gitea >/dev/null
5-
exec su-exec $USER /app/gitea/gitea web
5+
exec su-exec $USER /usr/local/bin/gitea web
66
popd

0 commit comments

Comments
 (0)