Skip to content

Commit

Permalink
fix: git chosen requires tag for checkout (#231)
Browse files Browse the repository at this point in the history
This is because if we accept values it will not be interpreted, and for git it means falling back on head, which is usually master

We'd rather want it to fail instead

Signed-off-by: Kasper J. Hermansen <contact@kjuulh.io>
  • Loading branch information
kjuulh committed Mar 15, 2024
1 parent d7c4377 commit 63c8542
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/plan_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"testing"
)

Expand All @@ -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 (#<branch / tag name>): something-invalid"),
},
{
name: "no plan with template",
input: args("-p", "testdata/project", "plan", "--template", "{{.PlanRaw}}"),
Expand Down
10 changes: 7 additions & 3 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (#<branch / tag name>): %s", planArgument)
}
}

planPath := path.Join(localShuttleDirectoryPath, "plan")
Expand Down

0 comments on commit 63c8542

Please sign in to comment.