aboutsummaryrefslogtreecommitdiff
path: root/refs_test.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-20 12:41:18 +0800
committerGravatar Runxi Yu2026-02-20 12:57:31 +0800
commite0e56e63defc1cb9cc14081c62bb268de7e15dd7 (patch)
tree9698d7daecb4775f500ac937646814a7a25bbe04 /refs_test.go
parentRevert "packed: Factor out packWriteObjects and clean up" (diff)
signatureNo signature
Revert "test: Make gitCmd accept an stdin []byte"
This reverts commit f762271dbfc121eaac7eb59c0beb01620a09118f.
Diffstat (limited to 'refs_test.go')
-rw-r--r--refs_test.go120
1 files changed, 60 insertions, 60 deletions
diff --git a/refs_test.go b/refs_test.go
index e15fd15b..2d4a1532 100644
--- a/refs_test.go
+++ b/refs_test.go
@@ -18,10 +18,10 @@ func TestResolveRef(t *testing.T) {
if err != nil {
t.Fatalf("Failed to write test.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "test")
- commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commitHash)
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "test")
+ commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "update-ref", "refs/heads/main", commitHash)
repo, err := OpenRepository(repoPath)
if err != nil {
@@ -42,7 +42,7 @@ func TestResolveRef(t *testing.T) {
t.Errorf("resolved hash: got %s, want %s", resolved.Hash, hashObj)
}
- gitRevParse := gitCmd(t, repoPath, nil, "rev-parse", "refs/heads/main")
+ gitRevParse := gitCmd(t, repoPath, "rev-parse", "refs/heads/main")
if resolved.Hash.String() != gitRevParse {
t.Errorf("furgit resolved %s, git resolved %s", resolved.Hash, gitRevParse)
}
@@ -64,11 +64,11 @@ func TestResolveHEAD(t *testing.T) {
if err != nil {
t.Fatalf("failed to write test.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "test")
- commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commitHash)
- gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD", "refs/heads/main")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "test")
+ commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "update-ref", "refs/heads/main", commitHash)
+ gitCmd(t, repoPath, "symbolic-ref", "HEAD", "refs/heads/main")
repo, err := OpenRepository(repoPath)
if err != nil {
@@ -89,7 +89,7 @@ func TestResolveHEAD(t *testing.T) {
t.Errorf("HEAD symbolic ref: got %q, want %q", ref.Ref, "refs/heads/main")
}
- gitSymRef := gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD")
+ gitSymRef := gitCmd(t, repoPath, "symbolic-ref", "HEAD")
if ref.Ref != gitSymRef {
t.Errorf("furgit resolved %v, git resolved %s", ref.Ref, gitSymRef)
}
@@ -106,23 +106,23 @@ func TestPackedRefs(t *testing.T) {
if err != nil {
t.Fatalf("failed to write test.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "commit1")
- commit1Hash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "commit1")
+ commit1Hash := gitCmd(t, repoPath, "rev-parse", "HEAD")
err = os.WriteFile(filepath.Join(workDir, "test2.txt"), []byte("content2"), 0o644)
if err != nil {
t.Fatalf("failed to write test2.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "commit2")
- commit2Hash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "commit2")
+ commit2Hash := gitCmd(t, repoPath, "rev-parse", "HEAD")
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/branch1", commit1Hash)
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/branch2", commit2Hash)
- gitCmd(t, repoPath, nil, "update-ref", "refs/tags/v1.0", commit1Hash)
+ gitCmd(t, repoPath, "update-ref", "refs/heads/branch1", commit1Hash)
+ gitCmd(t, repoPath, "update-ref", "refs/heads/branch2", commit2Hash)
+ gitCmd(t, repoPath, "update-ref", "refs/tags/v1.0", commit1Hash)
- gitCmd(t, repoPath, nil, "pack-refs", "--all")
+ gitCmd(t, repoPath, "pack-refs", "--all")
repo, err := OpenRepository(repoPath)
if err != nil {
@@ -141,7 +141,7 @@ func TestPackedRefs(t *testing.T) {
t.Errorf("branch1: got %s, want %s", resolved1.Hash, hash1)
}
- gitResolved1 := gitCmd(t, repoPath, nil, "rev-parse", "refs/heads/branch1")
+ gitResolved1 := gitCmd(t, repoPath, "rev-parse", "refs/heads/branch1")
if resolved1.Hash.String() != gitResolved1 {
t.Errorf("furgit resolved %s, git resolved %s", resolved1.Hash, gitResolved1)
}
@@ -175,14 +175,14 @@ func TestResolveRefFully(t *testing.T) {
if err != nil {
t.Fatalf("failed to write file.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "init")
- commit := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "init")
+ commit := gitCmd(t, repoPath, "rev-parse", "HEAD")
// Create two layers of symbolic refs
- gitCmd(t, repoPath, nil, "symbolic-ref", "refs/heads/level1", "refs/heads/level2")
- gitCmd(t, repoPath, nil, "symbolic-ref", "refs/heads/level2", "refs/heads/main")
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit)
+ gitCmd(t, repoPath, "symbolic-ref", "refs/heads/level1", "refs/heads/level2")
+ gitCmd(t, repoPath, "symbolic-ref", "refs/heads/level2", "refs/heads/main")
+ gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit)
repo, err := OpenRepository(repoPath)
if err != nil {
@@ -215,8 +215,8 @@ func TestResolveRefFullySymbolicCycle(t *testing.T) {
}
defer func() { _ = repo.Close() }()
- gitCmd(t, repoPath, nil, "symbolic-ref", "refs/heads/A", "refs/heads/B")
- gitCmd(t, repoPath, nil, "symbolic-ref", "refs/heads/B", "refs/heads/A")
+ gitCmd(t, repoPath, "symbolic-ref", "refs/heads/A", "refs/heads/B")
+ gitCmd(t, repoPath, "symbolic-ref", "refs/heads/B", "refs/heads/A")
_, err = repo.ResolveRefFully("refs/heads/A")
if err == nil {
@@ -239,10 +239,10 @@ func TestResolveRefHashInput(t *testing.T) {
if err != nil {
t.Fatalf("failed to write file.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "init")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "init")
- commitHash := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
+ commitHash := gitCmd(t, repoPath, "rev-parse", "HEAD")
repo, err := OpenRepository(repoPath)
if err != nil {
@@ -287,28 +287,28 @@ func TestListRefsLooseOverridesPacked(t *testing.T) {
workDir, cleanupWork := setupWorkDir(t)
defer cleanupWork()
- gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD", "refs/heads/main")
+ gitCmd(t, repoPath, "symbolic-ref", "HEAD", "refs/heads/main")
err := os.WriteFile(filepath.Join(workDir, "file.txt"), []byte("one"), 0o644)
if err != nil {
t.Fatalf("failed to write file.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "c1")
- commit1 := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "c1")
+ commit1 := gitCmd(t, repoPath, "rev-parse", "HEAD")
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit1)
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/feature", commit1)
- gitCmd(t, repoPath, nil, "pack-refs", "--all", "--prune")
+ gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit1)
+ gitCmd(t, repoPath, "update-ref", "refs/heads/feature", commit1)
+ gitCmd(t, repoPath, "pack-refs", "--all", "--prune")
err = os.WriteFile(filepath.Join(workDir, "file.txt"), []byte("two"), 0o644)
if err != nil {
t.Fatalf("failed to write file.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "c2")
- commit2 := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit2)
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "c2")
+ commit2 := gitCmd(t, repoPath, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit2)
repo, err := OpenRepository(repoPath)
if err != nil {
@@ -360,19 +360,19 @@ func TestListRefsPatternFiltering(t *testing.T) {
workDir, cleanupWork := setupWorkDir(t)
defer cleanupWork()
- gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD", "refs/heads/main")
+ gitCmd(t, repoPath, "symbolic-ref", "HEAD", "refs/heads/main")
err := os.WriteFile(filepath.Join(workDir, "file.txt"), []byte("one"), 0o644)
if err != nil {
t.Fatalf("failed to write file.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "c1")
- commit1 := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "c1")
+ commit1 := gitCmd(t, repoPath, "rev-parse", "HEAD")
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit1)
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/feature", commit1)
- gitCmd(t, repoPath, nil, "pack-refs", "--all", "--prune")
+ gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit1)
+ gitCmd(t, repoPath, "update-ref", "refs/heads/feature", commit1)
+ gitCmd(t, repoPath, "pack-refs", "--all", "--prune")
repo, err := OpenRepository(repoPath)
if err != nil {
@@ -404,21 +404,21 @@ func TestListRefsPackedPatterns(t *testing.T) {
workDir, cleanupWork := setupWorkDir(t)
defer cleanupWork()
- gitCmd(t, repoPath, nil, "symbolic-ref", "HEAD", "refs/heads/main")
+ gitCmd(t, repoPath, "symbolic-ref", "HEAD", "refs/heads/main")
err := os.WriteFile(filepath.Join(workDir, "file.txt"), []byte("one"), 0o644)
if err != nil {
t.Fatalf("failed to write file.txt: %v", err)
}
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "add", ".")
- gitCmd(t, repoPath, nil, "--work-tree="+workDir, "commit", "-m", "c1")
- commit := gitCmd(t, repoPath, nil, "rev-parse", "HEAD")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "add", ".")
+ gitCmd(t, repoPath, "--work-tree="+workDir, "commit", "-m", "c1")
+ commit := gitCmd(t, repoPath, "rev-parse", "HEAD")
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/main", commit)
- gitCmd(t, repoPath, nil, "update-ref", "refs/heads/feature/one", commit)
- gitCmd(t, repoPath, nil, "update-ref", "refs/notes/review", commit)
- gitCmd(t, repoPath, nil, "update-ref", "refs/tags/v1", commit)
- gitCmd(t, repoPath, nil, "pack-refs", "--all", "--prune")
+ gitCmd(t, repoPath, "update-ref", "refs/heads/main", commit)
+ gitCmd(t, repoPath, "update-ref", "refs/heads/feature/one", commit)
+ gitCmd(t, repoPath, "update-ref", "refs/notes/review", commit)
+ gitCmd(t, repoPath, "update-ref", "refs/tags/v1", commit)
+ gitCmd(t, repoPath, "pack-refs", "--all", "--prune")
repo, err := OpenRepository(repoPath)
if err != nil {