From e344b94d455712d9e753ef235bc6ff0e76fd91f2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 29 May 2026 17:14:38 +0300 Subject: fix(vq): restore version-prefix parsing and stash no-op handling --- internal/sync/git_operations_test.go | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 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 b80bf0e..4ca630d 100644 --- a/internal/sync/git_operations_test.go +++ b/internal/sync/git_operations_test.go @@ -120,6 +120,73 @@ func TestPopStash_RestoresStashedChanges(t *testing.T) { } } +func TestStashChanges_NoStashEntryReturnsFalse(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("committed\n"), 0o644); err != nil { + t.Fatalf("write tracked file: %v", err) + } + runGit(t, repoPath, "add", "tracked.txt") + runGit(t, repoPath, "commit", "-m", "initial") + + untrackedFile := filepath.Join(repoPath, "untracked.txt") + if err := os.WriteFile(untrackedFile, []byte("new\n"), 0o644); err != nil { + t.Fatalf("write untracked file: %v", err) + } + + stashed, err := stashChanges(repoPath) + if err != nil { + t.Fatalf("stashChanges() unexpected error: %v", err) + } + if stashed { + t.Fatal("stashChanges() = true, want false when no stash entry is created") + } + + if stashList := runGit(t, repoPath, "stash", "list"); stashList != "" { + t.Fatalf("expected no stash entries, got %q", stashList) + } +} + +func TestHandleWorkingDirectoryState_NoStashEntryReturnsNotStashed(t *testing.T) { + workDir := t.TempDir() + repoName := "repo" + repoPath := filepath.Join(workDir, repoName) + + if err := os.MkdirAll(repoPath, 0o755); err != nil { + t.Fatalf("mkdir repo path: %v", err) + } + + 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("committed\n"), 0o644); err != nil { + t.Fatalf("write tracked file: %v", err) + } + runGit(t, repoPath, "add", "tracked.txt") + runGit(t, repoPath, "commit", "-m", "initial") + + untrackedFile := filepath.Join(repoPath, "untracked.txt") + if err := os.WriteFile(untrackedFile, []byte("new\n"), 0o644); err != nil { + t.Fatalf("write untracked file: %v", err) + } + + s := &Syncer{workDir: workDir, repoName: repoName} + stashed, err := s.handleWorkingDirectoryState() + if err != nil { + t.Fatalf("handleWorkingDirectoryState() unexpected error: %v", err) + } + if stashed { + t.Fatal("handleWorkingDirectoryState() = true, want false when stash push creates no entry") + } +} + func runGit(t *testing.T, repoPath string, args ...string) string { t.Helper() -- cgit v1.2.3