From 976f720bfd2472b56490ac6d3f12b6e5fe80c03b Mon Sep 17 00:00:00 2001 From: Valentine Kiselev Date: Thu, 13 Oct 2022 10:52:58 +0300 Subject: [PATCH] fix: Don't uninstall lefthook.yml and lefthook-local.yml by default (#334) Signed-off-by: Valentin Kiselev --- cmd/uninstall.go | 17 ++++++++++++++--- internal/lefthook/uninstall.go | 6 +++--- internal/lefthook/uninstall_test.go | 17 ++++++++--------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 4edb2071..dca8dc49 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -17,15 +17,26 @@ func newUninstallCmd(opts *lefthook.Options) *cobra.Command { }, } + var deprecatedKeepConfig bool uninstallCmd.Flags().BoolVarP( - &args.KeepConfiguration, "keep-config", "k", false, - "keep configuration files and source directories present", + &deprecatedKeepConfig, "keep-config", "k", false, + "DEPRECATED: This option is enabled by default. It will be removed in next release.", ) uninstallCmd.Flags().BoolVarP( - &args.Aggressive, "aggressive", "a", false, + &args.Force, "aggressive", "a", false, + "DEPRECATED: will behave like -f/--force option", + ) + + uninstallCmd.Flags().BoolVarP( + &args.Force, "force", "f", false, "remove all git hooks even not lefthook-related", ) + uninstallCmd.Flags().BoolVarP( + &args.RemoveConfig, "remove-configs", "c", false, + "remove lefthook.yml and lefthook-local.yml", + ) + return &uninstallCmd } diff --git a/internal/lefthook/uninstall.go b/internal/lefthook/uninstall.go index ccef1cd2..dd9cc13e 100644 --- a/internal/lefthook/uninstall.go +++ b/internal/lefthook/uninstall.go @@ -9,7 +9,7 @@ import ( ) type UninstallArgs struct { - KeepConfiguration, Aggressive bool + Force, RemoveConfig bool } func Uninstall(opts *Options, args *UninstallArgs) error { @@ -22,11 +22,11 @@ func Uninstall(opts *Options, args *UninstallArgs) error { } func (l *Lefthook) Uninstall(args *UninstallArgs) error { - if err := l.deleteHooks(args.Aggressive || l.Options.Aggressive); err != nil { + if err := l.deleteHooks(args.Force || l.Options.Aggressive); err != nil { return err } - if !args.KeepConfiguration { + if args.RemoveConfig { for _, glob := range []string{ "lefthook.y*ml", "lefthook-local.y*ml", diff --git a/internal/lefthook/uninstall_test.go b/internal/lefthook/uninstall_test.go index 4acd596d..29dd7704 100644 --- a/internal/lefthook/uninstall_test.go +++ b/internal/lefthook/uninstall_test.go @@ -37,41 +37,40 @@ func TestLefthookUninstall(t *testing.T) { }, config: "# empty", wantExist: []string{ + configPath, hookPath("pre-commit"), }, wantNotExist: []string{ - configPath, hookPath("post-commit"), }, }, { - name: "with aggressive mode", - args: UninstallArgs{Aggressive: true}, + name: "with force", + args: UninstallArgs{Force: true}, existingHooks: map[string]string{ "pre-commit": "not a lefthook hook", "post-commit": "\n# LEFTHOOK file\n", }, config: "# empty", - wantExist: []string{}, + wantExist: []string{configPath}, wantNotExist: []string{ - configPath, hookPath("pre-commit"), hookPath("post-commit"), }, }, { - name: "with keep config arg", - args: UninstallArgs{KeepConfiguration: true}, + name: "with --remove-config option", + args: UninstallArgs{RemoveConfig: true}, existingHooks: map[string]string{ "pre-commit": "not a lefthook hook", "post-commit": "# LEFTHOOK", }, config: "# empty", wantExist: []string{ - configPath, hookPath("pre-commit"), }, wantNotExist: []string{ + configPath, hookPath("post-commit"), }, }, @@ -84,11 +83,11 @@ func TestLefthookUninstall(t *testing.T) { }, config: "# empty", wantExist: []string{ + configPath, hookPath("pre-commit"), hookPath("post-commit"), }, wantNotExist: []string{ - configPath, hookPath("post-commit.old"), }, },