-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Raj Nandan Sharma
authored and
Raj Nandan Sharma
committed
Apr 30, 2024
1 parent
24f2b42
commit 8697941
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,6 @@ | |
Thumbs.db | ||
|
||
.conventionalcommits/ | ||
.okgit/ | ||
dist/ | ||
bin/ | ||
.okgit/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cmd | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/rajnandan1/okgit/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var initCmd = &cobra.Command{ | ||
Use: "init", | ||
Short: "Add .okgit/ to the .gitignore file", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
gitignorePath := filepath.Join(".", ".gitignore") | ||
okgitPath := ".okgit/" | ||
|
||
// Read the contents of the .gitignore file | ||
data, err := ioutil.ReadFile(gitignorePath) | ||
if err != nil { | ||
utils.LogFatal(err) | ||
} | ||
|
||
// Append .okgit/ to the .gitignore file if it's not already present | ||
contents := string(data) | ||
if !strings.Contains(contents, okgitPath) { | ||
contents += okgitPath + "\n" | ||
|
||
// Write the updated contents back to the .gitignore file | ||
err = ioutil.WriteFile(gitignorePath, []byte(contents), 0644) | ||
if err != nil { | ||
utils.LogFatal(err) | ||
} | ||
|
||
utils.LogOutput(".okgit/ added to .gitignore file") | ||
} else { | ||
utils.LogOutput(".okgit/ already present in .gitignore file") | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(initCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters