summaryrefslogtreecommitdiff
path: root/internal/sync/git_operations_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-29 17:07:22 +0300
committerPaul Buetow <paul@buetow.org>2026-05-29 17:07:22 +0300
commitb076c5e2ac5403de28c5d0ba44fddf216f3034ce (patch)
treea979b40edc269005879d6be2c4a2fced4210156c /internal/sync/git_operations_test.go
parenta956a672859e92190149506197ad0fa682e964e2 (diff)
fix(vq): handle ignored stash/pop and parse errors explicitly
Diffstat (limited to 'internal/sync/git_operations_test.go')
-rw-r--r--internal/sync/git_operations_test.go43
1 files changed, 43 insertions, 0 deletions
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()