From b076c5e2ac5403de28c5d0ba44fddf216f3034ce Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 29 May 2026 17:07:22 +0300 Subject: fix(vq): handle ignored stash/pop and parse errors explicitly --- internal/sync/git_operations_test.go | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'internal/sync/git_operations_test.go') diff --git a/internal/sync/git_operations_test.go b/internal/sync/git_operations_test.go index e696fb7..b80bf0e 100644 --- a/internal/sync/git_operations_test.go +++ b/internal/sync/git_operations_test.go @@ -1,7 +1,9 @@ package sync import ( + "os" "os/exec" + "path/filepath" "strings" "testing" ) @@ -77,6 +79,47 @@ func TestGetTagCommitHash_LocalTagMissingReturnsError(t *testing.T) { } } +func TestPopStash_NoStashReturnsError(t *testing.T) { + repoPath := t.TempDir() + runGit(t, repoPath, "init") + + if err := popStash(repoPath); err == nil { + t.Fatal("expected error when popping stash with no entries") + } +} + +func TestPopStash_RestoresStashedChanges(t *testing.T) { + repoPath := t.TempDir() + + runGit(t, repoPath, "init") + runGit(t, repoPath, "config", "user.name", "Test User") + runGit(t, repoPath, "config", "user.email", "test@example.com") + + trackedFile := filepath.Join(repoPath, "tracked.txt") + if err := os.WriteFile(trackedFile, []byte("first\n"), 0o644); err != nil { + t.Fatalf("write tracked file: %v", err) + } + runGit(t, repoPath, "add", "tracked.txt") + runGit(t, repoPath, "commit", "-m", "initial") + + if err := os.WriteFile(trackedFile, []byte("second\n"), 0o644); err != nil { + t.Fatalf("update tracked file: %v", err) + } + runGit(t, repoPath, "stash", "push", "-m", "test-stash") + + if err := popStash(repoPath); err != nil { + t.Fatalf("expected popStash to succeed, got error: %v", err) + } + + content, err := os.ReadFile(trackedFile) + if err != nil { + t.Fatalf("read tracked file: %v", err) + } + if string(content) != "second\n" { + t.Fatalf("expected stashed content to be restored, got %q", string(content)) + } +} + func runGit(t *testing.T, repoPath string, args ...string) string { t.Helper() -- cgit v1.2.3