Add .gitignore creation and initial commit functionality
This commit is contained in:
35
main.go
35
main.go
@@ -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
|
||||||
|
Reference in New Issue
Block a user