(ctx context.Context)
| 14 | ) |
| 15 | |
| 16 | func check(ctx context.Context) error { |
| 17 | // Check if the Git command is available on the system's PATH |
| 18 | if !util.IsCommandAvailable("git") { |
| 19 | return errors.New( |
| 20 | "git command not found in your system's PATH. Please install Git and try again", |
| 21 | ) |
| 22 | } |
| 23 | |
| 24 | // Check if the current directory is a git repository and can execute git diff |
| 25 | g := git.New() |
| 26 | if err := g.CanExecuteGitDiff(ctx); err != nil { |
| 27 | return fmt.Errorf("cannot execute git diff: %w", err) |
| 28 | } |
| 29 | |
| 30 | // Apply configuration values from CLI flags to Viper |
| 31 | if diffUnified != 3 { |
| 32 | viper.Set("git.diff_unified", diffUnified) |
| 33 | } |
| 34 | |
| 35 | if len(excludeList) > 0 { |
| 36 | viper.Set("git.exclude_list", excludeList) |
| 37 | } |
| 38 | |
| 39 | if prompt.GetLanguage(commitLang) != prompt.DefaultLanguage { |
| 40 | viper.Set("output.lang", commitLang) |
| 41 | } |
| 42 | |
| 43 | if commitModel != openai.DefaultModel { |
| 44 | viper.Set("openai.model", commitModel) |
| 45 | } |
| 46 | |
| 47 | if httpsProxy != "" { |
| 48 | viper.Set("openai.proxy", httpsProxy) |
| 49 | } |
| 50 | |
| 51 | if socksProxy != "" { |
| 52 | viper.Set("openai.socks", socksProxy) |
| 53 | } |
| 54 | |
| 55 | if maxTokens != 300 { |
| 56 | viper.Set("openai.max_tokens", maxTokens) |
| 57 | } |
| 58 | |
| 59 | if templateFile != "" { |
| 60 | viper.Set("git.template_file", templateFile) |
| 61 | } |
| 62 | |
| 63 | if templateString != "" { |
| 64 | viper.Set("git.template_string", templateString) |
| 65 | } |
| 66 | |
| 67 | // Verify template file existence |
| 68 | cfgTemplateFile := viper.GetString("git.template_file") |
| 69 | if cfgTemplateFile != "" { |
| 70 | exists, err := file.IsFile(cfgTemplateFile) |
| 71 | if err != nil { |
| 72 | return fmt.Errorf("failed to check template file: %v", err) |
| 73 | } |
no test coverage detected