Skip to content

Commit

Permalink
fix: Uninstall remotes on lefthook uninstall
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>
  • Loading branch information
mrexox committed Nov 3, 2022
1 parent c145270 commit 71817fa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/remote/ping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

pre-commit:
commands:
pong:
ping:
run: echo pong
8 changes: 4 additions & 4 deletions internal/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pre-commit:
"test.sh":
runner: bash
`,
remoteConfigPath: filepath.Join(root, ".git", "info", "remotes", "lefthook", "lefthook.yml"),
remoteConfigPath: filepath.Join(root, ".git", "info", "lefthook-remotes", "lefthook", "lefthook.yml"),
result: &Config{
SourceDir: DefaultSourceDir,
SourceDirLocal: DefaultSourceDirLocal,
Expand Down Expand Up @@ -245,7 +245,7 @@ pre-commit:
"test.sh":
runner: bash
`,
remoteConfigPath: filepath.Join(root, ".git", "info", "remotes", "lefthook", "examples", "custom.yml"),
remoteConfigPath: filepath.Join(root, ".git", "info", "lefthook-remotes", "lefthook", "examples", "custom.yml"),
result: &Config{
SourceDir: DefaultSourceDir,
SourceDirLocal: DefaultSourceDirLocal,
Expand Down Expand Up @@ -308,7 +308,7 @@ pre-push:
remote:
run: echo remote
`,
remoteConfigPath: filepath.Join(root, ".git", "info", "remotes", "lefthook", "examples", "config.yml"),
remoteConfigPath: filepath.Join(root, ".git", "info", "lefthook-remotes", "lefthook", "examples", "config.yml"),
extends: map[string]string{
"global-extend.yml": `
pre-push:
Expand All @@ -322,7 +322,7 @@ pre-push:
"local-extend":
runner: bash
`,
".git/info/remotes/lefthook/remote-extend.yml": `
".git/info/lefthook-remotes/lefthook/remote-extend.yml": `
pre-push:
scripts:
"remote-extend":
Expand Down
13 changes: 9 additions & 4 deletions internal/git/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ import (
)

const (
remotesFolder = "remotes"
remotesFolder = "lefthook-remotes"
remotesFolderMode = 0o755
)

// RemoteFolder returns the path to the folder where the remote
// repository is located.
func (r *Repository) RemoteFolder(url string) string {
remotesPath := filepath.Join(r.InfoPath, remotesFolder)

return filepath.Join(
remotesPath,
r.RemotesFolder(),
filepath.Base(
strings.TrimSuffix(url, filepath.Ext(url)),
),
)
}

// RemotesFolder returns the path to the lefthook remotes folder.
func (r *Repository) RemotesFolder() string {
return filepath.Join(r.InfoPath, remotesFolder)
}

// SyncRemote clones or pulls the latest changes for a git repository that was
// specified as a remote config repository. If successful, the path to the root
// of the repository will be returned.
Expand Down
4 changes: 4 additions & 0 deletions internal/lefthook/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (l *Lefthook) Uninstall(args *UninstallArgs) error {
}
}

if err := l.Fs.RemoveAll(l.repo.RemotesFolder()); err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 71817fa

Please sign in to comment.