diff --git a/cmd/plan_test.go b/cmd/plan_test.go index 300a87e..dd010a3 100644 --- a/cmd/plan_test.go +++ b/cmd/plan_test.go @@ -1,6 +1,7 @@ package cmd import ( + "errors" "testing" ) @@ -20,6 +21,11 @@ func TestPlan(t *testing.T) { erroutput: "Cloning plan https://github.com/lunarway/shuttle-example-go-plan.git\n", err: nil, }, + { + name: "git plan invalid checkout", + input: args("-p", "testdata/project-git", "--plan", "something-invalid", "plan"), + initErr: errors.New("Plan argument wasn't valid for a git plan (#): something-invalid"), + }, { name: "no plan with template", input: args("-p", "testdata/project", "plan", "--template", "{{.PlanRaw}}"), diff --git a/pkg/git/git.go b/pkg/git/git.go index 7c52b0f..6b13982 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -83,9 +83,13 @@ func GetGitPlan( ) (string, error) { parsedGitPlan := ParsePlan(plan) - if strings.HasPrefix(planArgument, "#") { - parsedGitPlan.Head = planArgument[1:] - uii.EmphasizeInfoln("Overload git plan branch/tag/sha with %v", parsedGitPlan.Head) + if planArgument != "" { + if strings.HasPrefix(planArgument, "#") { + parsedGitPlan.Head = planArgument[1:] + uii.EmphasizeInfoln("Overload git plan branch/tag/sha with %v", parsedGitPlan.Head) + } else { + return "", fmt.Errorf("Plan argument wasn't valid for a git plan (#): %s", planArgument) + } } planPath := path.Join(localShuttleDirectoryPath, "plan")