Skip to content

Commit

Permalink
fix(projects): add check for git repo on init command
Browse files Browse the repository at this point in the history
  • Loading branch information
noetarbouriech committed Jul 12, 2023
1 parent 759fccf commit 48cf2b1
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"

"github.com/go-git/go-git/v5"
"github.com/paastech-cloud/cli/internal/config"
"github.com/paastech-cloud/cli/pkg/project"
"github.com/spf13/cobra"
Expand All @@ -17,11 +18,19 @@ var initCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Initializing a new project")

// Check if current directory is a git repo
_, err := git.PlainOpen(".")
if err != nil {
return errors.New("No git repository found in current directory")
}

// Load User config
userCfg, err := config.LoadAuthConfig()
if err != nil {
return err
}

// Check if user is authenticated
connected, err := config.IsAuthenticated(userCfg)
if err != nil {
return err
Expand All @@ -30,25 +39,30 @@ var initCmd = &cobra.Command{
return errors.New("Not logged in")
}

// Check if project exists
if config.ProjectExists() {
return errors.New("Project already exists")
}

// Create project
project, err := project.CreateProject(userCfg.GetString("server"), userCfg.GetString("jwt"), args[0])
if err != nil {
return err
}

// Create project conf
err = config.CreateProjectConfig()
if err != nil {
return err
}

// Load project config
projCfg, err := config.LoadProjectConfig()
if err != nil {
return err
}

// Write config
projCfg.Set("project", project)
projCfg.WriteConfig()

Expand Down
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,40 @@ require (
)

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/text v0.10.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/go-git/go-git/v5 v5.7.0
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.9.0 // indirect
Expand Down
Loading

0 comments on commit 48cf2b1

Please sign in to comment.