diff --git a/Dockerfile b/Dockerfile index adbde2e..1b08b2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/TODO.md b/TODO.md index 5fb0187..9ceb4d4 100644 --- a/TODO.md +++ b/TODO.md @@ -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) @@ -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 diff --git a/cmd/commit.go b/cmd/commit.go index 95ccd58..bad651d 100644 --- a/cmd/commit.go +++ b/cmd/commit.go @@ -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"} diff --git a/cmd/hooks.go b/cmd/hooks.go index 5e1ed0e..0299339 100644 --- a/cmd/hooks.go +++ b/cmd/hooks.go @@ -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) diff --git a/pkg/hooks.go b/pkg/hooks.go index db2b355..ae2d4ca 100644 --- a/pkg/hooks.go +++ b/pkg/hooks.go @@ -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 +}