Skip to content

Commit

Permalink
check dir exist before create/clone
Browse files Browse the repository at this point in the history
  • Loading branch information
zulkhair committed Oct 25, 2024
1 parent 84f5fb5 commit 1032212
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/world/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ func TestCreateStartStopRestartPurge(t *testing.T) {
// set tea ouput to variable
teaOut := &bytes.Buffer{}
createCmd := getCreateCmd(teaOut)
createCmd.SetArgs([]string{gameDir})

// checkout the repo
sgtDir := gameDir + "/sgt"
createCmd.SetArgs([]string{sgtDir})
err = createCmd.Execute()
assert.NilError(t, err)

// Change dir
err = os.Chdir(sgtDir)
assert.NilError(t, err)

// Start cardinal
rootCmd.SetArgs([]string{"cardinal", "start", "--detach", "--editor=false"})
err = rootCmd.Execute()
Expand Down Expand Up @@ -173,6 +179,9 @@ func TestDev(t *testing.T) {
createCmd := getCreateCmd(teaOut)
createCmd.SetArgs([]string{gameDir})

// checkout the repo
sgtDir := gameDir + "/sgt"
createCmd.SetArgs([]string{sgtDir})
err = createCmd.Execute()
assert.NilError(t, err)

Expand Down
6 changes: 6 additions & 0 deletions common/teacmd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func git(args ...string) (string, error) {
}

func GitCloneCmd(url string, targetDir string, initMsg string) error {
// check targetDir exists
if _, err := os.Stat(targetDir); err == nil {
return eris.Errorf("Game shard named '%s' already exists in this directory, "+
"please change the directory or use another name", targetDir)
}

_, err := git("clone", url, targetDir)
if err != nil {
return err
Expand Down

0 comments on commit 1032212

Please sign in to comment.