Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
check for .git on env pull if no-git before
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 25, 2020
1 parent 206b416 commit 51a3196
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/commands/envcmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/martinnirtl/dockma/pkg/externalcommand"
"github.com/martinnirtl/dockma/pkg/externalcommand/spinnertimebridger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/ttacon/chalk"
)

Expand Down Expand Up @@ -55,9 +56,24 @@ func runPullCommand(cmd *cobra.Command, args []string) {
envHomeDir := env.GetHomeDir()

if !env.IsGitBased() {
fmt.Printf("Environment %s is not a git repository.\n", chalk.Cyan.Color(envName))
err := os.Chdir(envHomeDir)
if err != nil {
fmt.Println(err)
utils.ErrorAndExit(fmt.Errorf("Could not change to path %s", chalk.Underline.TextStyle(envHomeDir)))
}

// FIXME duplicated code > see env init cmd
if _, err := os.Stat(".git"); !os.IsNotExist(err) {
pull := survey.Select(fmt.Sprintf("Run %s before %s", chalk.Cyan.Color("git pull"), chalk.Cyan.Color("dockma up")), []string{"auto", "optional", "manual", "off"})

viper.Set(fmt.Sprintf("envs.%s.pull", envName), pull)

os.Exit(0)
config.Save(fmt.Sprintf("Saved pull setting for environment: %s", chalk.Cyan.Color(envName)), errors.New("Failed to save pull setting"))
} else {
fmt.Printf("Environment %s is %s.\n", chalk.Cyan.Color(envName), chalk.Red.Color("not a git repository"))

os.Exit(0)
}
}

hideCmdOutput := config.GetHideSubcommandOutputSetting()
Expand Down

0 comments on commit 51a3196

Please sign in to comment.