From f1e7f748d08cf894dc431b710f02057a31315d97 Mon Sep 17 00:00:00 2001 From: system Date: Tue, 20 May 2025 12:19:09 +0200 Subject: [PATCH] Add .gitignore creation and initial commit functionality --- main.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/main.go b/main.go index 2c51e07..8c3035f 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,41 @@ func doRun() { return } 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 { logger.Error("Error opening repository: %v", err) return