1
0
Fork 0
mirror of https://github.com/imjasonh/infinite-git synced 2026-07-19 07:13:32 +00:00

Update to use single hello.txt file instead of creating new files

Instead of creating a new file for each pull (pull_1.txt, pull_2.txt, etc.),
now updates a single hello.txt file with the pull number and timestamp
with nanosecond precision.

Changes:
- Modified commit generator to update hello.txt instead of creating new files
- Added hello.txt to initial repository commit
- Updated tests to verify hello.txt content instead of checking for new files
- Fixed test expectations to account for counter increment during clone

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jason Hall 2025-07-23 22:56:40 -04:00
parent 45d3788735
commit db0c5c91a5
Failed to extract signature
3 changed files with 42 additions and 18 deletions

View file

@ -63,26 +63,28 @@ func (g *Generator) GenerateCommit() (string, error) {
// Parse existing tree entries // Parse existing tree entries
existingEntries := parseTree(parentTreeData) existingEntries := parseTree(parentTreeData)
// Create new file content // Create updated hello.txt content with nanosecond precision
filename := fmt.Sprintf("pull_%d.txt", count) filename := "hello.txt"
content := fmt.Sprintf("Pull request #%d\nTimestamp: %s\n", count, time.Now().Format(time.RFC3339)) content := fmt.Sprintf("Pull #%d\nTimestamp: %s\n", count, time.Now().Format("2006-01-02 15:04:05.999999999"))
// Create blob for new file // Create blob for updated file
blob := object.NewBlob([]byte(content)) blob := object.NewBlob([]byte(content))
blobHash, err := g.repo.WriteObject(blob) blobHash, err := g.repo.WriteObject(blob)
if err != nil { if err != nil {
return "", fmt.Errorf("writing blob: %w", err) return "", fmt.Errorf("writing blob: %w", err)
} }
// Create new tree with all existing entries plus new file // Create new tree with all existing entries, replacing hello.txt
tree := object.NewTree() tree := object.NewTree()
// Add existing entries // Add existing entries, but skip hello.txt as we'll add the updated one
for _, entry := range existingEntries { for _, entry := range existingEntries {
tree.AddEntry(entry.Mode, entry.Name, entry.Hash) if entry.Name != filename {
tree.AddEntry(entry.Mode, entry.Name, entry.Hash)
}
} }
// Add new file // Add updated hello.txt
tree.AddEntry("100644", filename, blobHash) tree.AddEntry("100644", filename, blobHash)
treeHash, err := g.repo.WriteObject(tree) treeHash, err := g.repo.WriteObject(tree)

View file

@ -91,15 +91,24 @@ func (r *Repository) createInitialCommit() error {
readmeContent := []byte("# Infinite Git Repository\n\nThis repository generates a new commit every time you pull.\n") readmeContent := []byte("# Infinite Git Repository\n\nThis repository generates a new commit every time you pull.\n")
// Create blob for README // Create blob for README
blob := object.NewBlob(readmeContent) readmeBlob := object.NewBlob(readmeContent)
blobHash, err := object.Write(r.gitDir, blob) readmeBlobHash, err := object.Write(r.gitDir, readmeBlob)
if err != nil { if err != nil {
return fmt.Errorf("writing blob: %w", err) return fmt.Errorf("writing README blob: %w", err)
} }
// Create tree with README // Create initial hello.txt content
helloContent := []byte("Pull #0\nTimestamp: Initial commit\n")
helloBlob := object.NewBlob(helloContent)
helloBlobHash, err := object.Write(r.gitDir, helloBlob)
if err != nil {
return fmt.Errorf("writing hello.txt blob: %w", err)
}
// Create tree with README and hello.txt
tree := object.NewTree() tree := object.NewTree()
tree.AddEntry("100644", "README.md", blobHash) tree.AddEntry("100644", "README.md", readmeBlobHash)
tree.AddEntry("100644", "hello.txt", helloBlobHash)
treeHash, err := object.Write(r.gitDir, tree) treeHash, err := object.Write(r.gitDir, tree)
if err != nil { if err != nil {
return fmt.Errorf("writing tree: %w", err) return fmt.Errorf("writing tree: %w", err)
@ -124,12 +133,17 @@ func (r *Repository) createInitialCommit() error {
return fmt.Errorf("updating ref: %w", err) return fmt.Errorf("updating ref: %w", err)
} }
// Also write README to working directory // Also write README and hello.txt to working directory
readmePath := filepath.Join(r.path, "README.md") readmePath := filepath.Join(r.path, "README.md")
if err := os.WriteFile(readmePath, readmeContent, 0644); err != nil { if err := os.WriteFile(readmePath, readmeContent, 0644); err != nil {
return fmt.Errorf("writing README to working directory: %w", err) return fmt.Errorf("writing README to working directory: %w", err)
} }
helloPath := filepath.Join(r.path, "hello.txt")
if err := os.WriteFile(helloPath, helloContent, 0644); err != nil {
return fmt.Errorf("writing hello.txt to working directory: %w", err)
}
return nil return nil
} }

View file

@ -5,6 +5,7 @@ import (
"net/http/httptest" "net/http/httptest"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"sync" "sync"
"testing" "testing"
@ -89,10 +90,17 @@ func TestCloneAndPull(t *testing.T) {
t.Errorf("expected %d commits after pull %d, got %d", initialCount+i+1, i+1, newCount) t.Errorf("expected %d commits after pull %d, got %d", initialCount+i+1, i+1, newCount)
} }
// Verify new files exist // Verify hello.txt exists and has been updated
expectedFile := filepath.Join(clientRepoDir, fmt.Sprintf("pull_%d.txt", i+1)) helloFile := filepath.Join(clientRepoDir, "hello.txt")
if _, err := os.Stat(expectedFile); os.IsNotExist(err) { content, err := os.ReadFile(helloFile)
t.Errorf("expected file %s does not exist", expectedFile) if err != nil {
t.Errorf("failed to read hello.txt: %v", err)
} else {
// Clone increments counter to 1, so first pull is #2, second is #3, etc.
expectedContent := fmt.Sprintf("Pull #%d\n", i+2)
if !strings.Contains(string(content), expectedContent) {
t.Errorf("hello.txt does not contain expected content %q, got: %s", expectedContent, content)
}
} }
} }