From 09c2a03cefa687832257d3b816da50db3cfcc0f2 Mon Sep 17 00:00:00 2001
From: ai_xiaopei <xiaopei@aisim.cn>
Date: Sat, 25 Jul 2026 23:48:11 +0800
Subject: [PATCH] feat: 实现输出格式化
---
internal/index/cache_test.go | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/internal/index/cache_test.go b/internal/index/cache_test.go
new file mode 100644
index 0000000..d686b14
--- /dev/null
+++ b/internal/index/cache_test.go
@@ -0,0 +1,35 @@
+package index
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+ "testing"
+)
+
+func TestGetGitCommit(t *testing.T) {
+ // 创建临时 git 仓库
+ tmpDir := t.TempDir()
+ exec.Command("git", "-C", tmpDir, "init").Run()
+ exec.Command("git", "-C", tmpDir, "config", "user.email", "test@test.com").Run()
+ exec.Command("git", "-C", tmpDir, "config", "user.name", "test").Run()
+ os.WriteFile(filepath.Join(tmpDir, "test.md"), []byte("test"), 0644)
+ exec.Command("git", "-C", tmpDir, "add", ".").Run()
+ exec.Command("git", "-C", tmpDir, "commit", "-m", "init").Run()
+
+ commit, err := GetGitCommit(tmpDir)
+ if err != nil {
+ t.Fatalf("GetGitCommit failed: %v", err)
+ }
+ if len(commit) != 40 {
+ t.Errorf("commit length = %d, want 40", len(commit))
+ }
+}
+
+func TestGetGitCommitNotGit(t *testing.T) {
+ tmpDir := t.TempDir()
+ _, err := GetGitCommit(tmpDir)
+ if err == nil {
+ t.Error("expected error for non-git directory")
+ }
+}
--
Gitblit v1.9.1