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

Commit

Permalink
check if env is git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 19, 2020
1 parent ac6bf37 commit 7c3c999
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions internal/commands/envcmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -142,7 +143,7 @@ func GetEnv(name string) (Env, error) {
}

return &env{
name: viper.GetString("active"),
name: name,
}, nil
}

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 7c3c999

Please sign in to comment.