85b462536a167d3538cafb7f658fe144a544be47

Author
Christopher David Shirk <1655014+christophershirk@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix: add missing arg length check to fix runtime panic (#568)

* Add missing arg length check to fix runtime panic on "repo branch delete <reponame>" command with missing branch arg

* Add testscript case for missing argument

---------

Co-authored-by: x2 <x2@rrotn.local>

Diff

 1diff --git a/pkg/ssh/cmd/branch.go b/pkg/ssh/cmd/branch.go
 2index c43ce974f69d6d117d2e80bb91d580f578f6e928..daa0efaa0500e6a952ad5a078abf690624b61a6b 100644
 3--- a/pkg/ssh/cmd/branch.go
 4+++ b/pkg/ssh/cmd/branch.go
 5@@ -148,6 +148,7 @@ func branchDeleteCommand() *cobra.Command {
 6 		Use:               "delete REPOSITORY BRANCH",
 7 		Aliases:           []string{"remove", "rm", "del"},
 8 		Short:             "Delete a branch",
 9+		Args:              cobra.ExactArgs(2),
10 		PersistentPreRunE: checkIfCollab,
11 		RunE: func(cmd *cobra.Command, args []string) error {
12 			ctx := cmd.Context()
13diff --git a/testscript/testdata/repo-delete.txtar b/testscript/testdata/repo-delete.txtar
14index 403c96043cd4ec46e448b17954ad346e7cceeca4..ca513e782523d1325e986f87cde1af38308b1628 100644
15--- a/testscript/testdata/repo-delete.txtar
16+++ b/testscript/testdata/repo-delete.txtar
17@@ -10,6 +10,11 @@ soft repo create repo-to-delete
18 soft repo delete repo-to-delete
19 ! soft repo delete nope
20 stderr '.*not found.*'
21+
22+# missing argument should fail
23+! soft repo branch delete repo1
24+stderr 'Error.*accepts 2 arg.*'
25+
26 soft repo list
27 stdout 'repo1'
28