From 7c3c99998635f7dc0ba09a5ea295fa5027cda72f Mon Sep 17 00:00:00 2001 From: Martin Nirtl Date: Wed, 19 Feb 2020 10:38:38 +0100 Subject: [PATCH] check if env is git repo --- internal/commands/envcmd/pull.go | 11 +++++++++-- internal/config/config.go | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/commands/envcmd/pull.go b/internal/commands/envcmd/pull.go index c459a9b..0714798 100644 --- a/internal/commands/envcmd/pull.go +++ b/internal/commands/envcmd/pull.go @@ -27,16 +27,23 @@ var pullCommand = &cobra.Command{ } else { envName = helpers.GetEnvironment(args[0]) } + env, err := config.GetEnv(envName) utils.ErrorAndExit(err) envHomeDir := env.GetHomeDir() + if !env.IsGitBased() { + fmt.Printf("Environment %s is not a git repository.\n", chalk.Cyan.Color(envName)) + + os.Exit(0) + } + hideCmdOutput := config.GetHideSubcommandOutputSetting() output, err := Pull(envHomeDir, hideCmdOutput, true) if err != nil && hideCmdOutput { - fmt.Println(string(output)) + fmt.Print(string(output)) } utils.ErrorAndExit(err) @@ -70,7 +77,7 @@ func Pull(path string, hideCmdOutput bool, writeToDockmaLog bool) (output []byte output, cmdErr := externalcommand.Execute("git pull", timebridger, logfile) if cmdErr != nil { - err = errors.New("Could not execute 'git pull' in active environment home dir") + err = errors.New("Could not execute 'git pull'") } // activeEnv.SetUpdated() // TODO make config to object diff --git a/internal/config/config.go b/internal/config/config.go index 4a8acc7..35c5f3b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -33,6 +33,7 @@ type Env interface { SetUpdated() (time.Time, error) LastUpdate() (time.Duration, error) GetPullSetting() string + IsGitBased() bool GetProfileNames() []string HasProfile(name string) bool GetProfile(name string) (Profile, error) @@ -142,7 +143,7 @@ func GetEnv(name string) (Env, error) { } return &env{ - name: viper.GetString("active"), + name: name, }, nil } @@ -188,6 +189,11 @@ func (e *env) GetPullSetting() string { return viper.GetString(fmt.Sprintf("envs.%s.pull", e.name)) } +// IsGitBased returns whether environment is versioned with git or not. +func (e *env) IsGitBased() bool { + return viper.GetString(fmt.Sprintf("envs.%s.pull", e.name)) != "no-git" +} + // GetProfilesNames returns profile names for given env. func (e *env) GetProfileNames() (profiles []string) { for profile := range viper.GetStringMap(fmt.Sprintf("envs.%s.profiles", e.name)) {