From 4401cda1736e543f22cb798ff3ad27ed2b743d14 Mon Sep 17 00:00:00 2001 From: zulkhair Date: Mon, 23 Sep 2024 18:34:29 +0000 Subject: [PATCH] fix: check git configuration before exec world create (#74) 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 --- common/teacmd/git.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/common/teacmd/git.go b/common/teacmd/git.go index 53d2243..5a613be 100644 --- a/common/teacmd/git.go +++ b/common/teacmd/git.go @@ -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": "no-reply@world.dev", + } + + _, err := sh.Exec(env, &outBuff, &errBuff, "git", args...) if err != nil { return "", err } @@ -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 \"", "-m", initMsg) if err != nil { return err }