From e5e1a1c15572e9061f5c852edf6ce486a067b0b6 Mon Sep 17 00:00:00 2001
From: Jessica Yuen <im.jessicayuen@gmail.com>
Date: Tue, 26 Sep 2017 14:22:09 -0700
Subject: [PATCH] Fix 'env set' where --name flag is not specified

There is a bug where if --name is not passed during env set, an error is
thrown due to failed validation checking on an empty name. This commit
fixes this bug.
---
 metadata/environment.go | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/metadata/environment.go b/metadata/environment.go
index 8e23beb1..e9243996 100644
--- a/metadata/environment.go
+++ b/metadata/environment.go
@@ -246,14 +246,14 @@ func (m *manager) SetEnvironment(name string, desired *Environment) error {
 		return fmt.Errorf("Environment '%s' does not exist", name)
 	}
 
-	// ensure new environment name does not contain punctuation
-	if !isValidName(desired.Name) {
-		return fmt.Errorf("Environment name '%s' is not valid; must not contain punctuation, spaces, or begin or end with a slash", name)
-	}
-
 	// If the name has changed, the directory location needs to be moved to
 	// reflect the change.
 	if name != desired.Name && len(desired.Name) != 0 {
+		// ensure new environment name does not contain punctuation
+		if !isValidName(desired.Name) {
+			return fmt.Errorf("Environment name '%s' is not valid; must not contain punctuation, spaces, or begin or end with a slash", name)
+		}
+
 		log.Infof("Setting environment name from '%s' to '%s'", name, desired.Name)
 
 		// Ensure not overwriting another environment
-- 
GitLab