Skip to content

Commit

Permalink
fix: check git configuration before exec world create (#74)
Browse files Browse the repository at this point in the history
Closes: WORLD-1177

## Overview

When user trying to exec `world create` but git configuration `.gitconfig` for username and password is not configured it will be returned error, but the gameshard dir is already created.

The issue is because on the last step of `world create` it will exec git commit, and it will need username and email to be configured in `.gitconfig`

Solutions
Before executing `world create`, world cli will check the git configuration is configured or not. if it's not, world cli will tell the command how to configure the git config.

## Brief Changelog

- Create func for checking git configuration
- Call the function at the first execution of `world create` command

## Testing and Verifying
- Added unit test for checkGitConfig func
  • Loading branch information
zulkhair committed Sep 23, 2024
1 parent 6eee015 commit 4401cda
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions common/teacmd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ type GitCloneFinishMsg struct {

func git(args ...string) (string, error) {
var outBuff, errBuff bytes.Buffer
_, err := sh.Exec(nil, &outBuff, &errBuff, "git", args...)

// Define environment variables
env := map[string]string{
"GIT_COMMITTER_NAME": "World CLI",
"GIT_COMMITTER_EMAIL": "[email protected]",
}

_, err := sh.Exec(env, &outBuff, &errBuff, "git", args...)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -94,7 +101,7 @@ func GitCloneCmd(url string, targetDir string, initMsg string) error {
return err
}

_, err = git("commit", "-m", initMsg)
_, err = git("commit", "--author=\"World CLI <[email protected]>\"", "-m", initMsg)
if err != nil {
return err
}
Expand Down

0 comments on commit 4401cda

Please sign in to comment.