Skip to content

Commit

Permalink
Deprecate maintainOnlyServerHooks in favor of maintainedHooks ⚓ (#76
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gabyx authored Dec 19, 2021
1 parent b4a05b0 commit 4c54578
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,7 @@ can then attach to the debug server with the debug configuration

### Todos:

- Test: `githooks.disableSharedHooksUpdate`.
- Finish deploy settings implementation for Gitea and sorts.
- Finish deploy settings implementation for Gitea and others.

## Changelog

Expand Down
12 changes: 12 additions & 0 deletions githooks/cmd/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,8 @@ func runUpdate(

log.InfoF("Running install to version '%s' ...", build.BuildVersion)

transformLegacyGitConfigSettings(log, gitx)

// Read registered file if existing.
// We ensured during load, that only existing Git directories are listed.
err := settings.RegisteredGitDirs.Load(settings.InstallDir, true, true)
Expand Down Expand Up @@ -1369,3 +1371,13 @@ func runInstall(cmd *cobra.Command, ctx *ccm.CmdContext, vi *viper.Viper) {
"occurred!", logStats.ErrorCount(), logStats.WarningCount())
}
}

func transformLegacyGitConfigSettings(log cm.ILogContext, gitx *git.Context) {
useOnlyServerHooks := gitx.GetConfig("githooks.maintainOnlyServerHooks", git.GlobalScope)
if useOnlyServerHooks == git.GitCVTrue {
err := hooks.SetMaintainedHooks(gitx, []string{"server"}, git.GlobalScope)
log.AssertNoError(err, "Could not set maintained hooks to 'server'.")
}

_ = git.Ctx().UnsetConfig("githooks.maintainOnlyServerHooks", git.GlobalScope)
}
3 changes: 3 additions & 0 deletions githooks/cmd/uninstaller/uninstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ func cleanGitConfig(log cm.ILogContext, gitx *git.Context) {
k := "githooks.checksumCacheDir"
log.AssertNoErrorF(gitx.UnsetConfig(k, git.GlobalScope),
"Could not unset global Git config '%s'.", k)
k = "githooks.maintainOnlyServerHooks"
log.AssertNoErrorF(gitx.UnsetConfig(k, git.GlobalScope),
"Could not unset global Git config '%s'.", k)
}

func cleanRegister(log cm.ILogContext, installDir string) {
Expand Down
3 changes: 0 additions & 3 deletions githooks/hooks/gitconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const (

GitCKDisable = "githooks.disable"

GitCKMaintainOnlyServerHooks = "githooks.maintainOnlyServerHooks" // deprecate

GitCKAutoUpdateEnabled = "githooks.autoUpdateEnabled"
GitCKAutoUpdateCheckTimestamp = "githooks.autoUpdateCheckTimestamp"
GitCKAutoUpdateUsePrerelease = "githooks.autoUpdateUsePrerelease"
Expand Down Expand Up @@ -61,7 +59,6 @@ func GetGlobalGitConfigKeys() []string {

GitCKDisable,

GitCKMaintainOnlyServerHooks, // deprecate
GitCKMaintainedHooks,
GitCKPreviousSearchDir,

Expand Down
5 changes: 0 additions & 5 deletions githooks/hooks/hook-names.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ func SetMaintainedHooks(
maintainedHooks = append(maintainedHooks, "all")
}

// Deprecation
if scope == git.GlobalScope {
_ = git.Ctx().UnsetConfig(GitCKMaintainOnlyServerHooks, scope)
}

err = git.Ctx().SetConfig(GitCKMaintainedHooks, strings.Join(maintainedHooks, ", "), scope)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion githooks/scripts/clean-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo "Unset all githooks configs ..."
git config --global --unset githooks.runner
git config --global --unset-all githooks.shared
git config --global --unset githooks.failOnNonExistingSharedHooks
git config --global --unset githooks.maintainOnlyServerHooks
git config --global --unset githooks.maintainedHooks
git config --global --unset githooks.autoUpdateEnabled
git config --global --unset githooks.autoUpdateCheckTimestamp
git config --global --unset githooks.cloneUrl
Expand Down

0 comments on commit 4c54578

Please sign in to comment.