fix(hook): 支持 --cached/--staged 参数并优化 pre-commit 脚本
This commit is contained in:
1 parent
0b4d02d232
commit
1493b0a392
3 files changed
+14
-8
No files matched your search
+5
-6
@@ -43,12 +43,11 @@ func LoadConfig() (*AppConfig, error) {
|
|||||||
|
|
||||||
// 1. 首先加载全局配置 ~/.git-air/config.yaml
|
// 1. 首先加载全局配置 ~/.git-air/config.yaml
|
||||||
configPath, err := getConfigPath()
|
configPath, err := getConfigPath()
|
||||||
if err == nil {
|
if err != nil {
|
||||||
if data, err := os.ReadFile(configPath); err == nil && len(data) > 0 {
|
// 隐式跳过时,可考虑记录日志或在 verbose 模式下输出
|
||||||
if err := yaml.Unmarshal(data, cfg); err != nil {
|
} else if data, err := os.ReadFile(configPath); err == nil && len(data) > 0 {
|
||||||
// 全局配置错误可输出警告或直接返回错误
|
if err := yaml.Unmarshal(data, cfg); err != nil {
|
||||||
return nil, fmt.Errorf("解析全局配置文件 [%s] 失败: %w", configPath, err)
|
return nil, fmt.Errorf("解析全局配置文件 [%s] 失败: %w", configPath, err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -12,8 +12,7 @@ import (
|
|||||||
const preCommitScript = `#!/bin/sh
|
const preCommitScript = `#!/bin/sh
|
||||||
# git-air pre-commit hook
|
# git-air pre-commit hook
|
||||||
echo "[git-air] 正在执行 Commit 前代码自动化评审..."
|
echo "[git-air] 正在执行 Commit 前代码自动化评审..."
|
||||||
git-air --cached
|
git-air
|
||||||
# 如果评审发现阻断性问题,可通过退出码阻断 commit
|
|
||||||
`
|
`
|
||||||
|
|
||||||
var hookCmd = &cobra.Command{
|
var hookCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ var rootCmd = &cobra.Command{
|
|||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
|
|
||||||
// 1. 检查并获取 Diff
|
// 1. 检查并获取 Diff
|
||||||
|
if flagCached, _ := cmd.Flags().GetBool("cached"); flagCached {
|
||||||
|
args = append([]string{"--cached"}, args...)
|
||||||
|
} else if flagStaged, _ := cmd.Flags().GetBool("staged"); flagStaged {
|
||||||
|
args = append([]string{"--cached"}, args...)
|
||||||
|
}
|
||||||
|
|
||||||
diff, err := git.GetDiff(ctx, args...)
|
diff, err := git.GetDiff(ctx, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.PrintError("%v", err)
|
ui.PrintError("%v", err)
|
||||||
@@ -99,4 +105,6 @@ func init() {
|
|||||||
rootCmd.Flags().StringP("model", "m", "", "临时指定模型名称")
|
rootCmd.Flags().StringP("model", "m", "", "临时指定模型名称")
|
||||||
rootCmd.Flags().StringP("provider", "p", "", "临时指定 Provider (gemini, deepseek, ollama)")
|
rootCmd.Flags().StringP("provider", "p", "", "临时指定 Provider (gemini, deepseek, ollama)")
|
||||||
rootCmd.Flags().String("prompt", "", "临时指定 System Prompt")
|
rootCmd.Flags().String("prompt", "", "临时指定 System Prompt")
|
||||||
|
rootCmd.Flags().Bool("cached", false, "显式审查暂存区(git add)代码")
|
||||||
|
rootCmd.Flags().Bool("staged", false, "显式审查暂存区(git add)代码")
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user