Skip to content

Commit e86381a

Browse files
authored
Merge pull request #543 from oasisprotocol/andrej/bugfix/rofl-init-git
cmd/rofl: Fix git repository initialization
2 parents dc6ac7e + 65feade commit e86381a

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

cmd/rofl/mgmt.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"context"
77
_ "embed"
88
"encoding/json"
9-
"errors"
109
"fmt"
1110
"io"
1211
"os"
@@ -117,10 +116,15 @@ var (
117116
cobra.CheckErr(fmt.Errorf("failed to write manifest: %w", err))
118117
}
119118

120-
// Initialize git repository if not already present.
121-
_, err = os.Stat(".git")
122-
if err != nil && errors.Is(err, os.ErrNotExist) {
123-
// Git directory doesn't exist, try to initialize.
119+
// Check if we're inside an existing git repository.
120+
var gitRepoExists bool
121+
gitRevParseCmd := exec.Command("git", "rev-parse")
122+
if err = gitRevParseCmd.Run(); err == nil {
123+
gitRepoExists = true
124+
}
125+
126+
if !gitRepoExists {
127+
// Initialize a new git repository in the app directory.
124128
gitInitCmd := exec.Command("git", "init")
125129
if err = gitInitCmd.Run(); err != nil {
126130
fmt.Printf("Git repository not initialized: %s.\n", err)
@@ -129,7 +133,7 @@ var (
129133
}
130134
}
131135

132-
// Initialize .gitignore.
136+
// Initialize .gitignore in the app directory.
133137
needToAddOrcIgnore := true
134138
gitignore, err := os.Open(".gitignore")
135139
if err == nil {

0 commit comments

Comments
 (0)