Skip to content

Commit

Permalink
fix: remove lefthook.checksum on uninstall (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliusHenke authored Nov 16, 2022
1 parent b7c9afc commit 6d71a66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/lefthook/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func (l *Lefthook) Uninstall(args *UninstallArgs) error {
return err
}

if err := l.Fs.Remove(l.checksumFilePath()); err == nil {
log.Debugf("%s removed", l.checksumFilePath())
} else {
log.Errorf("Failed removing %s: %s\n", l.checksumFilePath(), err)
}

if args.RemoveConfig {
for _, glob := range []string{
"lefthook.y*ml",
Expand Down
17 changes: 16 additions & 1 deletion internal/lefthook/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/spf13/afero"

"github.com/evilmartians/lefthook/internal/config"
"github.com/evilmartians/lefthook/internal/git"
)

Expand All @@ -17,7 +18,10 @@ func TestLefthookUninstall(t *testing.T) {
}

configPath := filepath.Join(root, "lefthook.yml")
hooksPath := filepath.Join(root, ".git", "hooks")
gitPath := filepath.Join(root, ".git")
hooksPath := filepath.Join(gitPath, "hooks")
infoPath := filepath.Join(gitPath, "info")
checksumPath := filepath.Join(infoPath, config.ChecksumFileName)

hookPath := func(hook string) string {
return filepath.Join(root, ".git", "hooks", hook)
Expand All @@ -41,6 +45,7 @@ func TestLefthookUninstall(t *testing.T) {
hookPath("pre-commit"),
},
wantNotExist: []string{
checksumPath,
hookPath("post-commit"),
},
},
Expand All @@ -54,6 +59,7 @@ func TestLefthookUninstall(t *testing.T) {
config: "# empty",
wantExist: []string{configPath},
wantNotExist: []string{
checksumPath,
hookPath("pre-commit"),
hookPath("post-commit"),
},
Expand All @@ -70,6 +76,7 @@ func TestLefthookUninstall(t *testing.T) {
hookPath("pre-commit"),
},
wantNotExist: []string{
checksumPath,
configPath,
hookPath("post-commit"),
},
Expand All @@ -88,6 +95,7 @@ func TestLefthookUninstall(t *testing.T) {
hookPath("post-commit"),
},
wantNotExist: []string{
checksumPath,
hookPath("post-commit.old"),
},
},
Expand All @@ -100,13 +108,20 @@ func TestLefthookUninstall(t *testing.T) {
Fs: fs,
HooksPath: hooksPath,
RootPath: root,
GitPath: gitPath,
InfoPath: infoPath,
},
}

// Create config and checksum file
err := afero.WriteFile(fs, configPath, []byte(tt.config), 0o644)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
err = afero.WriteFile(fs, checksumPath, []byte("CHECKSUM"), 0o644)
if err != nil {
t.Errorf("unexpected error: %s", err)
}

// Prepare files that should exist
for hook, content := range tt.existingHooks {
Expand Down

0 comments on commit 6d71a66

Please sign in to comment.