Skip to content

Commit

Permalink
feat: add check for installed hooks 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasAugustin committed Aug 10, 2023
1 parent 8567b97 commit cb0c367
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#######################################
# image for dev build environment
######################################
FROM alpine:3.18.2 as DEV
FROM golang:1.21-alpine3.18 as DEV
# install packages
RUN apk add --update --no-cache bash make git zsh curl tmux

Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- [x] git hook wrong command name
- [ ] lots of tests missing
- [x] local cache for list (use viper with config file)
- [ ] add check for hook and disable commit if hook is created
- [x] add check for hook and disable commit if hook is created
- [ ] commands
- [x] list -> use list bubbles prompt and local cache in homedir
- [x] search -> remove (merge with list)
Expand All @@ -20,6 +20,7 @@
- [x] message
- [ ] add 2nd message optional
- [ ] add flags for message, scope,.. and prefill
- [ ] config option for commit message formats
- [x] config -> write config as local config file (with prompt)
- [x] possibility to use env variables
- [x] add -g --global flag for global configuration
Expand Down
11 changes: 10 additions & 1 deletion cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ to quickly create a Cobra application.`,
log.Debug(commitMsg)
spin := ui.NewSpinner()
spin.Run()

existentHookFiles, err := pkg.HookFilesExistent()
if err != nil {
log.Fatalf("Error checking if hook files existent")
}
if len(existentHookFiles) > 0 {
log.Infof("There are hook files existen for %s", existentHookFiles)
log.Infof("Please use git commit command or remove the hooks with %s hooks rm", pkg.ProgramName)
spin.Stop()
return
}
gitmojis := pkg.GetGitmojis()
spin.Stop()
listSettings := ui.ListSettings{IsShowStatusBar: true, IsFilteringEnabled: true, Title: "Gitmojis"}
Expand Down
2 changes: 1 addition & 1 deletion cmd/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
log.Debug("hooks init called")
log.Debug("hooks rm called")
err := pkg.RemoveAllHookFiles()
if err != nil {
log.Error(err)
Expand Down
19 changes: 19 additions & 0 deletions pkg/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,22 @@ func RemoveAllHookFiles() error {

return nil
}

func HookFilesExistent() ([]string, error) {
hooksDir, hooksErr := utils.GetGitRepoHooksDirectory()
if hooksErr != nil {
return []string{}, ErrInvalidGitHooksDirectoryPath
}

var existentHooks []string

for _, hook := range gitHooks {
hookPath := filepath.Join(hooksDir, hook)
exists := utils.FileExists(hookPath)
if exists {
existentHooks = append(existentHooks, hook)
}
}

return existentHooks, nil
}

0 comments on commit cb0c367

Please sign in to comment.