Skip to content

Commit 7a2daae

Browse files
Sync git hooks when config file path changed (#21619) (#21625)
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 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 5bc3fbd commit 7a2daae

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

modules/appstate/item_runtime.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ package appstate
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
@@ -74,21 +74,31 @@ func InitGitServices() {
7474
mustInit(repo_service.Init)
7575
}
7676

77-
func syncAppPathForGit(ctx context.Context) error {
77+
func syncAppConfForGit(ctx context.Context) error {
7878
runtimeState := new(appstate.RuntimeState)
7979
if err := appstate.AppState.Get(runtimeState); err != nil {
8080
return err
8181
}
82+
83+
updated := false
8284
if runtimeState.LastAppPath != setting.AppPath {
8385
log.Info("AppPath changed from '%s' to '%s'", runtimeState.LastAppPath, setting.AppPath)
86+
runtimeState.LastAppPath = setting.AppPath
87+
updated = true
88+
}
89+
if runtimeState.LastCustomConf != setting.CustomConf {
90+
log.Info("CustomConf changed from '%s' to '%s'", runtimeState.LastCustomConf, setting.CustomConf)
91+
runtimeState.LastCustomConf = setting.CustomConf
92+
updated = true
93+
}
8494

95+
if updated {
8596
log.Info("re-sync repository hooks ...")
8697
mustInitCtx(ctx, repo_service.SyncRepositoryHooks)
8798

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

91-
runtimeState.LastAppPath = setting.AppPath
92102
return appstate.AppState.Set(runtimeState)
93103
}
94104
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)