From 65feade4fafd68a66f4debc46eb9c69e469ce838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Buko=C5=A1ek?= Date: Wed, 16 Jul 2025 16:31:33 +0200 Subject: [PATCH] cmd/rofl: Fix git repository initialization --- cmd/rofl/mgmt.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/rofl/mgmt.go b/cmd/rofl/mgmt.go index dc3d950b..8e6453fc 100644 --- a/cmd/rofl/mgmt.go +++ b/cmd/rofl/mgmt.go @@ -6,7 +6,6 @@ import ( "context" _ "embed" "encoding/json" - "errors" "fmt" "io" "os" @@ -117,10 +116,15 @@ var ( cobra.CheckErr(fmt.Errorf("failed to write manifest: %w", err)) } - // Initialize git repository if not already present. - _, err = os.Stat(".git") - if err != nil && errors.Is(err, os.ErrNotExist) { - // Git directory doesn't exist, try to initialize. + // Check if we're inside an existing git repository. + var gitRepoExists bool + gitRevParseCmd := exec.Command("git", "rev-parse") + if err = gitRevParseCmd.Run(); err == nil { + gitRepoExists = true + } + + if !gitRepoExists { + // Initialize a new git repository in the app directory. gitInitCmd := exec.Command("git", "init") if err = gitInitCmd.Run(); err != nil { fmt.Printf("Git repository not initialized: %s.\n", err) @@ -129,7 +133,7 @@ var ( } } - // Initialize .gitignore. + // Initialize .gitignore in the app directory. needToAddOrcIgnore := true gitignore, err := os.Open(".gitignore") if err == nil {