From 433d2747f8bcd67d55c7e7f725a5c18172fc5e64 Mon Sep 17 00:00:00 2001 From: Patel230 Date: Tue, 9 Jun 2026 18:41:17 +0530 Subject: [PATCH] Harden git watcher test setup --- git/watcher_test.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/git/watcher_test.go b/git/watcher_test.go index e428f1c..6fd6510 100644 --- a/git/watcher_test.go +++ b/git/watcher_test.go @@ -17,24 +17,29 @@ func setupTestRepo(t *testing.T) (string, storage.Storage, graph.Graph) { t.Helper() dir := t.TempDir() - // Initialize a git repo + runGit := func(args ...string) { + t.Helper() + cmd := exec.Command("git", args...) + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("git %v: %s: %v", args, out, err) + } + } + cmd := exec.Command("git", "init", dir) if out, err := cmd.CombinedOutput(); err != nil { t.Fatalf("git init: %s: %v", out, err) } - // Configure git user for commits - cmd = exec.Command("git", "-C", dir, "config", "user.email", "test@test.com") - cmd.Run() - cmd = exec.Command("git", "-C", dir, "config", "user.name", "Test") - cmd.Run() + runGit("-C", dir, "config", "user.email", "test@test.com") + runGit("-C", dir, "config", "user.name", "Test") + runGit("-C", dir, "config", "commit.gpgsign", "false") - // Create a file and initial commit if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte("package main\n"), 0o644); err != nil { t.Fatal(err) } - exec.Command("git", "-C", dir, "add", ".").Run() - exec.Command("git", "-C", dir, "commit", "-m", "init").Run() + runGit("-C", dir, "add", ".") + runGit("-C", dir, "commit", "-m", "init") dbDir := t.TempDir() store, err := storage.NewStore(filepath.Join(dbDir, "test.db"))