Skip to content

Commit

Permalink
fix: Don't uninstall lefthook.yml and lefthook-local.yml by default (#…
Browse files Browse the repository at this point in the history
…334)

Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>
  • Loading branch information
mrexox authored Oct 13, 2022
1 parent 2aacf3b commit 976f720
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
17 changes: 14 additions & 3 deletions cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions internal/lefthook/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type UninstallArgs struct {
KeepConfiguration, Aggressive bool
Force, RemoveConfig bool
}

func Uninstall(opts *Options, args *UninstallArgs) error {
Expand All @@ -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",
Expand Down
17 changes: 8 additions & 9 deletions internal/lefthook/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
},
Expand All @@ -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"),
},
},
Expand Down

0 comments on commit 976f720

Please sign in to comment.