@@ -796,32 +796,79 @@ def publish(ctx, version: Optional[str], list_drafts: bool, delete_drafts: bool,
796796 console .print (f"[dim]{ preview } [/dim]\n " )
797797 else :
798798 # Create and push git tag before creating GitHub release
799- if not git_ops .tag_exists (tag_name , remote = False ):
799+ tag_exists_locally = git_ops .tag_exists (tag_name , remote = False )
800+ tag_exists_remotely = git_ops .tag_exists (tag_name , remote = True )
801+ should_force_tag = force != 'none'
802+
803+ # Handle local tag
804+ if not tag_exists_locally :
800805 if debug :
801806 console .print (f"[dim]Creating git tag { tag_name } at { target_branch } ...[/dim]" )
802807 try :
803808 git_ops .create_tag (tag_name , ref = target_branch , message = f"Release { version } " )
804809 if debug :
805810 console .print (f"[dim]✓ Created local tag { tag_name } [/dim]" )
811+ else :
812+ console .print (f"[blue]✓ Created local tag { tag_name } [/blue]" )
806813 except Exception as e :
807814 console .print (f"[red]Error creating git tag: { e } [/red]" )
808815 sys .exit (1 )
816+ elif should_force_tag :
817+ # Delete and recreate local tag when forcing
818+ if debug :
819+ console .print (f"[dim]Force: Deleting and recreating local tag { tag_name } at { target_branch } ...[/dim]" )
820+ try :
821+ git_ops .repo .delete_tag (tag_name )
822+ git_ops .create_tag (tag_name , ref = target_branch , message = f"Release { version } " )
823+ if debug :
824+ console .print (f"[dim]✓ Force-created local tag { tag_name } [/dim]" )
825+ else :
826+ console .print (f"[blue]✓ Force-created local tag { tag_name } [/blue]" )
827+ except Exception as e :
828+ console .print (f"[red]Error force-creating git tag: { e } [/red]" )
829+ sys .exit (1 )
809830 elif debug :
810831 console .print (f"[dim]Tag { tag_name } already exists locally[/dim]" )
811832
812833 # Push tag to remote
813- if not git_ops . tag_exists ( tag_name , remote = True ) :
834+ if not tag_exists_remotely :
814835 if debug :
815836 console .print (f"[dim]Pushing tag { tag_name } to remote...[/dim]" )
816837 try :
817838 git_ops .push_tag (tag_name )
818839 if debug :
819840 console .print (f"[dim]✓ Pushed tag { tag_name } to remote[/dim]" )
841+ else :
842+ console .print (f"[blue]✓ Pushed tag { tag_name } to remote[/blue]" )
820843 except Exception as e :
821844 console .print (f"[red]Error pushing git tag: { e } [/red]" )
822845 sys .exit (1 )
823- elif debug :
824- console .print (f"[dim]Tag { tag_name } already exists on remote[/dim]" )
846+ elif should_force_tag :
847+ # Force push tag when forcing
848+ if debug :
849+ console .print (f"[dim]Force-pushing tag { tag_name } to remote...[/dim]" )
850+ try :
851+ git_ops .push_tag (tag_name , force = True )
852+ if debug :
853+ console .print (f"[dim]✓ Force-pushed tag { tag_name } to remote[/dim]" )
854+ else :
855+ console .print (f"[blue]✓ Force-pushed tag { tag_name } to remote[/blue]" )
856+ except Exception as e :
857+ console .print (f"[red]Error force-pushing git tag: { e } [/red]" )
858+ sys .exit (1 )
859+ else :
860+ if debug :
861+ console .print (f"[dim]Tag { tag_name } already exists on remote[/dim]" )
862+ # Even if tag exists, still try to push in case local is ahead
863+ # This handles the case where the tag might exist but not be on the correct commit
864+ try :
865+ git_ops .push_tag (tag_name )
866+ if debug :
867+ console .print (f"[dim]✓ Pushed tag { tag_name } to remote (update)[/dim]" )
868+ except Exception as e :
869+ # Non-fatal - tag might already be at correct commit
870+ if debug :
871+ console .print (f"[dim]Tag push skipped (already up to date or would fail): { e } [/dim]" )
825872
826873 console .print (f"[blue]Creating { status } GitHub release for { version } ...[/blue]" )
827874
0 commit comments