Add .gitignore creation and initial commit functionality

This commit is contained in:
system
2025-05-20 12:19:09 +02:00
parent 5f7441ed8b
commit f1e7f748d0

35
main.go
View File

@@ -60,6 +60,41 @@ func doRun() {
return return
} }
logger.Info("New repository created at: %s", ROOT) logger.Info("New repository created at: %s", ROOT)
// Create .gitignore file
gitignorePath := filepath.Join(ROOT, ".gitignore")
if err := os.WriteFile(gitignorePath, []byte("*.log\n"), 0644); err != nil {
logger.Error("Error creating .gitignore: %v", err)
return
}
// Get the worktree for initial commit
w, err := r.Worktree()
if err != nil {
logger.Error("Error getting worktree: %v", err)
return
}
// Add .gitignore
if _, err := w.Add(".gitignore"); err != nil {
logger.Error("Error adding .gitignore: %v", err)
return
}
// Create initial commit
if _, err := w.Commit("Initial commit", &git.CommitOptions{
Author: &object.Signature{
Name: "system",
Email: "system@localhost",
When: time.Now(),
},
}); err != nil {
logger.Error("Error creating initial commit: %v", err)
return
}
logger.Info("Initial commit created with .gitignore")
return
} else { } else {
logger.Error("Error opening repository: %v", err) logger.Error("Error opening repository: %v", err)
return return