1
0
Fork 0
mirror of https://github.com/imjasonh/infinite-git synced 2026-07-18 14:55:01 +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
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)

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")
// 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
}