Skip to content

Commit e4a10f8

Browse files
wolfogretechknowlogickzeripath
authored
Sync git hooks when config file path changed (#21619) (#21626)
Backport #21619 . A patch to #17335. Just like AppPath, Gitea writes its own CustomConf into git hook scripts too. If Gitea's CustomConf changes, then the git push may fail. Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: zeripath <art27@cantab.net>
1 parent 6dba648 commit e4a10f8

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

modules/system/item_runtime.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ package system
66

77
// RuntimeState contains app state for runtime, and we can save remote version for update checker here in future
88
type RuntimeState struct {
9-
LastAppPath string `json:"last_app_path"`
9+
LastAppPath string `json:"last_app_path"`
10+
LastCustomConf string `json:"last_custom_conf"`
1011
}
1112

1213
// Name returns the item name

routers/init.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,31 @@ func InitGitServices() {
7676
mustInit(repo_service.Init)
7777
}
7878

79-
func syncAppPathForGit(ctx context.Context) error {
79+
func syncAppConfForGit(ctx context.Context) error {
8080
runtimeState := new(system.RuntimeState)
8181
if err := system.AppState.Get(runtimeState); err != nil {
8282
return err
8383
}
84+
85+
updated := false
8486
if runtimeState.LastAppPath != setting.AppPath {
8587
log.Info("AppPath changed from '%s' to '%s'", runtimeState.LastAppPath, setting.AppPath)
88+
runtimeState.LastAppPath = setting.AppPath
89+
updated = true
90+
}
91+
if runtimeState.LastCustomConf != setting.CustomConf {
92+
log.Info("CustomConf changed from '%s' to '%s'", runtimeState.LastCustomConf, setting.CustomConf)
93+
runtimeState.LastCustomConf = setting.CustomConf
94+
updated = true
95+
}
8696

97+
if updated {
8798
log.Info("re-sync repository hooks ...")
8899
mustInitCtx(ctx, repo_service.SyncRepositoryHooks)
89100

90101
log.Info("re-write ssh public keys ...")
91102
mustInit(asymkey_model.RewriteAllPublicKeys)
92103

93-
runtimeState.LastAppPath = setting.AppPath
94104
return system.AppState.Set(runtimeState)
95105
}
96106
return nil
@@ -153,7 +163,7 @@ func GlobalInitInstalled(ctx context.Context) {
153163
mustInit(repo_migrations.Init)
154164
eventsource.GetManager().Init()
155165

156-
mustInitCtx(ctx, syncAppPathForGit)
166+
mustInitCtx(ctx, syncAppConfForGit)
157167

158168
mustInit(ssh.Init)
159169

0 commit comments

Comments
 (0)