fix(cli): reject empty --tag on release upload, test through execution · git-pkgs/forge@c87889d · GitHub
Skip to content

Commit c87889d

Browse files
fix(cli): reject empty --tag on release upload, test through execution
andrew (re-review on #172): --tag='' bypassed conflict validation and fell through to positional mode. uploadTagAndFile now takes Changed("tag") and rejects an explicitly empty flag value, so an unset script variable cannot silently select positional mode. Tests run the command end to end for both supported forms and the invalid combinations, asserting the tag and file contents passed to UploadAsset (and zero calls on refusal). Signed-off-by: Rene Turcios <95189389+CloudCorpRecords@users.noreply.github.com>
1 parent e628914 commit c87889d

3 files changed

Lines changed: 142 additions & 28 deletions

File tree

‎internal/cli/pr_checkout_test.go‎

Lines changed: 4 additions & 3 deletions

‎internal/cli/release.go‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,14 @@ func releaseDeleteCmd() *cobra.Command {
313313
}
314314

315315
// uploadTagAndFile resolves the release tag and file for "release upload". The tag comes from --tag with the file as
316-
// the only argument, or from the first of two positional arguments.
317-
func uploadTagAndFile(flagTag string, args []string) (tag, file string, err error) {
318-
if flagTag != "" {
316+
// the only argument, or from the first of two positional arguments. tagChanged must be
317+
// cmd.Flags().Changed("tag"): an explicitly empty --tag is an error, not an unset flag, so an
318+
// unset script variable cannot silently select positional mode.
319+
func uploadTagAndFile(flagTag string, tagChanged bool, args []string) (tag, file string, err error) {
320+
if tagChanged {
321+
if flagTag == "" {
322+
return "", "", fmt.Errorf("--tag value must not be empty")
323+
}
319324
if len(args) != 1 {
320325
return "", "", fmt.Errorf("with --tag, expected one <file> argument, got %d", len(args))
321326
}
@@ -334,11 +339,11 @@ func releaseUploadCmd() *cobra.Command {
334339
Use: "upload (<tag> <file> | --tag <tag> <file>)",
335340
Short: "Upload an asset to a release",
336341
Args: func(cmd *cobra.Command, args []string) error {
337-
_, _, err := uploadTagAndFile(flagTag, args)
342+
_, _, err := uploadTagAndFile(flagTag, cmd.Flags().Changed("tag"), args)
338343
return err
339344
},
340345
RunE: func(cmd *cobra.Command, args []string) error {
341-
tag, filePath, err := uploadTagAndFile(flagTag, args)
346+
tag, filePath, err := uploadTagAndFile(flagTag, cmd.Flags().Changed("tag"), args)
342347
if err != nil {
343348
return err
344349
}

‎internal/cli/release_test.go‎

Lines changed: 128 additions & 20 deletions

0 commit comments

Comments
 (0)