From 85b462536a167d3538cafb7f658fe144a544be47 Mon Sep 17 00:00:00 2001 From: Christopher David Shirk <1655014+christophershirk@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:38:36 -0500 Subject: [PATCH] fix: add missing arg length check to fix runtime panic (#568) * Add missing arg length check to fix runtime panic on "repo branch delete " command with missing branch arg * Add testscript case for missing argument --------- Co-authored-by: x2 --- pkg/ssh/cmd/branch.go | 1 + testscript/testdata/repo-delete.txtar | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/pkg/ssh/cmd/branch.go b/pkg/ssh/cmd/branch.go index c43ce974f..daa0efaa0 100644 --- a/pkg/ssh/cmd/branch.go +++ b/pkg/ssh/cmd/branch.go @@ -148,6 +148,7 @@ func branchDeleteCommand() *cobra.Command { Use: "delete REPOSITORY BRANCH", Aliases: []string{"remove", "rm", "del"}, Short: "Delete a branch", + Args: cobra.ExactArgs(2), PersistentPreRunE: checkIfCollab, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() diff --git a/testscript/testdata/repo-delete.txtar b/testscript/testdata/repo-delete.txtar index 403c96043..ca513e782 100644 --- a/testscript/testdata/repo-delete.txtar +++ b/testscript/testdata/repo-delete.txtar @@ -10,6 +10,11 @@ soft repo create repo-to-delete soft repo delete repo-to-delete ! soft repo delete nope stderr '.*not found.*' + +# missing argument should fail +! soft repo branch delete repo1 +stderr 'Error.*accepts 2 arg.*' + soft repo list stdout 'repo1'