Skip to content

Commit 3735b88

Browse files
Add .gitignore file creation in init command
- Implemented a function to create a .gitignore file during the initialization of Codacy configuration. - Updated .gitignore to include cli-v2 and removed unnecessary entries. - Ensured the .gitignore file contains relevant entries for Codacy CLI tools.
1 parent 0c06807 commit 3735b88

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,4 @@ go.work.sum
2525
.vscode/
2626

2727
# Codacy CLI
28-
cli-v2
29-
.codacy/cli-config.yaml
30-
.codacy/tools-configs
31-
.codacy/tools-configs/*
28+
cli-v2

cmd/init.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var initCmd = &cobra.Command{
5656
if err != nil {
5757
log.Fatal(err)
5858
}
59+
createGitIgnoreFile()
5960
}
6061
fmt.Println()
6162
fmt.Println("✅ Successfully initialized Codacy configuration!")
@@ -67,6 +68,27 @@ var initCmd = &cobra.Command{
6768
},
6869
}
6970

71+
func createGitIgnoreFile() error {
72+
gitIgnorePath := filepath.Join(config.Config.LocalCodacyDirectory(), ".gitignore")
73+
gitIgnoreFile, err := os.Create(gitIgnorePath)
74+
if err != nil {
75+
return fmt.Errorf("failed to create .gitignore file: %w", err)
76+
}
77+
defer gitIgnoreFile.Close()
78+
79+
content := `# Codacy CLI
80+
tools-configs
81+
tools-configs/*
82+
.gitignore
83+
cli-config.yaml
84+
`
85+
if _, err := gitIgnoreFile.WriteString(content); err != nil {
86+
return fmt.Errorf("failed to write to .gitignore file: %w", err)
87+
}
88+
89+
return nil
90+
}
91+
7092
func createConfigurationFiles(tools []tools.Tool, cliLocalMode bool) error {
7193
configFile, err := os.Create(config.Config.ProjectConfigFile())
7294
defer configFile.Close()

0 commit comments

Comments
 (0)