@@ -360,6 +360,8 @@ func NewRelease(ctx *context.Context) {
360360 return
361361 }
362362
363+ ctx .Data ["ShowCreateTagOnlyButton" ] = true
364+
363365 // pre-fill the form with the tag name, target branch and the existing release (if exists)
364366 ctx .Data ["tag_target" ] = ctx .Repo .Repository .DefaultBranch
365367 if tagName := ctx .FormString ("tag" ); tagName != "" {
@@ -376,7 +378,7 @@ func NewRelease(ctx *context.Context) {
376378 return
377379 }
378380
379- ctx .Data ["TagNameReleaseExists " ] = true
381+ ctx .Data ["ShowCreateTagOnlyButton " ] = false
380382 ctx .Data ["tag_name" ] = rel .TagName
381383 ctx .Data ["tag_target" ] = rel .Target
382384 ctx .Data ["title" ] = rel .Title
@@ -397,14 +399,17 @@ func NewReleasePost(ctx *context.Context) {
397399
398400 form := web .GetForm (ctx ).(* forms.NewReleaseForm )
399401
400- // first, check whether the release exists,
401- // it should be done before the form error check, because the tmpl needs "TagNameReleaseExists" to show/hide the "tag only" button
402+ // first, check whether the release exists, and prepare "ShowCreateTagOnlyButton"
403+ // the logic should be done before the form error check to make the tmpl has correct variables
402404 rel , err := repo_model .GetRelease (ctx , ctx .Repo .Repository .ID , form .TagName )
403405 if err != nil && ! repo_model .IsErrReleaseNotExist (err ) {
404406 ctx .ServerError ("GetRelease" , err )
405407 return
406408 }
407- ctx .Data ["TagNameReleaseExists" ] = rel != nil
409+
410+ // we should still show the "tag only" button if the user clicks it, no matter the release exists or not.
411+ // because if error occurs, end users need to have the chance to edit the name and submit the form with "tag-only" again.
412+ ctx .Data ["ShowCreateTagOnlyButton" ] = form .TagOnly || rel == nil
408413
409414 // do some form checks
410415 if ctx .HasError () {
0 commit comments