diff options
author | Philip Peterson <philip-peterson@users.noreply.github.com> | 2023-03-13 00:51:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 15:51:07 +0800 |
commit | 757b4c17e900f1d11a81bc9467d90e6c245ee8f2 (patch) | |
tree | d73ad5cfdcd0b7db80ee26461b946f68223e7fb8 /modules/git | |
parent | f521e88240a2d5dd41ee42d78b96fc89309f1790 (diff) | |
download | gitea-757b4c17e900f1d11a81bc9467d90e6c245ee8f2.tar.gz gitea-757b4c17e900f1d11a81bc9467d90e6c245ee8f2.zip |
Support reflogs (#22451)
This PR adds support for reflogs on all repositories. It does this by
adding a global configuration entry.
Implements #14865
---------
Signed-off-by: Philip Peterson <philip.c.peterson@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/git.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/git/git.go b/modules/git/git.go index 24cfea8c7f..a31afc077a 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -201,6 +201,23 @@ func InitFull(ctx context.Context) (err error) { return syncGitConfig() } +func enableReflogs() error { + if err := configSet("core.logAllRefUpdates", "true"); err != nil { + return err + } + err := configSet("gc.reflogExpire", fmt.Sprintf("%d", setting.Git.Reflog.Expiration)) + return err +} + +func disableReflogs() error { + if err := configUnsetAll("core.logAllRefUpdates", "true"); err != nil { + return err + } else if err := configUnsetAll("gc.reflogExpire", ""); err != nil { + return err + } + return nil +} + // syncGitConfig only modifies gitconfig, won't change global variables (otherwise there will be data-race problem) func syncGitConfig() (err error) { if err = os.MkdirAll(HomeDir(), os.ModePerm); err != nil { @@ -224,6 +241,16 @@ func syncGitConfig() (err error) { return err } + if setting.Git.Reflog.Enabled { + if err := enableReflogs(); err != nil { + return err + } + } else { + if err := disableReflogs(); err != nil { + return err + } + } + if CheckGitVersionAtLeast("2.10") == nil { if err := configSet("receive.advertisePushOptions", "true"); err != nil { return err |