mirror of
https://github.com/imjasonh/infinite-git
synced 2026-07-08 00:55:26 +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:
parent
45d3788735
commit
db0c5c91a5
3 changed files with 42 additions and 18 deletions
|
|
@ -63,26 +63,28 @@ func (g *Generator) GenerateCommit() (string, error) {
|
|||
// Parse existing tree entries
|
||||
existingEntries := parseTree(parentTreeData)
|
||||
|
||||
// Create new file content
|
||||
filename := fmt.Sprintf("pull_%d.txt", count)
|
||||
content := fmt.Sprintf("Pull request #%d\nTimestamp: %s\n", count, time.Now().Format(time.RFC3339))
|
||||
// Create updated hello.txt content with nanosecond precision
|
||||
filename := "hello.txt"
|
||||
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))
|
||||
blobHash, err := g.repo.WriteObject(blob)
|
||||
if err != nil {
|
||||
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()
|
||||
|
||||
// Add existing entries
|
||||
// Add existing entries, but skip hello.txt as we'll add the updated one
|
||||
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)
|
||||
|
||||
treeHash, err := g.repo.WriteObject(tree)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
// Create blob for README
|
||||
blob := object.NewBlob(readmeContent)
|
||||
blobHash, err := object.Write(r.gitDir, blob)
|
||||
readmeBlob := object.NewBlob(readmeContent)
|
||||
readmeBlobHash, err := object.Write(r.gitDir, readmeBlob)
|
||||
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.AddEntry("100644", "README.md", blobHash)
|
||||
tree.AddEntry("100644", "README.md", readmeBlobHash)
|
||||
tree.AddEntry("100644", "hello.txt", helloBlobHash)
|
||||
treeHash, err := object.Write(r.gitDir, tree)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing tree: %w", err)
|
||||
|
|
@ -124,12 +133,17 @@ func (r *Repository) createInitialCommit() error {
|
|||
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")
|
||||
if err := os.WriteFile(readmePath, readmeContent, 0644); err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
16
main_test.go
16
main_test.go
|
|
@ -5,6 +5,7 @@ import (
|
|||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"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)
|
||||
}
|
||||
|
||||
// Verify new files exist
|
||||
expectedFile := filepath.Join(clientRepoDir, fmt.Sprintf("pull_%d.txt", i+1))
|
||||
if _, err := os.Stat(expectedFile); os.IsNotExist(err) {
|
||||
t.Errorf("expected file %s does not exist", expectedFile)
|
||||
// Verify hello.txt exists and has been updated
|
||||
helloFile := filepath.Join(clientRepoDir, "hello.txt")
|
||||
content, err := os.ReadFile(helloFile)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue