feat(cmd): 优化提交命令的暂存区交互逻辑并支持上下文控制
- 新增 -a/--all 标志以支持自动暂存所有已修改的文件 - 增加对暂存区状态的检测,未暂存时提供友好的交互提示 - 为 Git 执行函数引入 context.Context 支持,确保超时与取消机制正常运作
This commit is contained in:
1 parent
6eda653db6
commit
c7e8b449c9
2 files changed
+51
-8
No files matched your search
@@ -32,6 +32,21 @@ func GetRepoRoot(ctx context.Context) (string, error) {
|
||||
return strings.TrimSpace(string(out)), nil
|
||||
}
|
||||
|
||||
// HasStagedChanges 检查当前 Git 暂存区是否有待提交的文件改动
|
||||
func HasStagedChanges(ctx context.Context) (bool, error) {
|
||||
stagedDiff, err := execGitDiff(ctx, "--cached")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return strings.TrimSpace(stagedDiff) != "", nil
|
||||
}
|
||||
|
||||
// StageAll 执行 git add -A 暂存当前所有改动
|
||||
func StageAll(ctx context.Context) error {
|
||||
cmd := exec.CommandContext(ctx, "git", "add", "-A")
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
const maxDiffSize = 300 * 1024 // 限制最大 300KB Diff,避免打爆上下文与 OOM
|
||||
|
||||
// GetDiff 提取并过滤 Git 代码差异
|
||||
|
||||
Reference in new issue
Block a user