Skip to content

Commit 6bed519

Browse files
committed
wip
1 parent 0653efd commit 6bed519

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

src/release_tool/commands/publish.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/release_tool/git_ops.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,19 @@ def create_tag(self, tag_name: str, ref: str = "HEAD", message: Optional[str] =
242242
else:
243243
self.repo.create_tag(tag_name, ref=ref)
244244

245-
def push_tag(self, tag_name: str, remote: str = "origin") -> None:
245+
def push_tag(self, tag_name: str, remote: str = "origin", force: bool = False) -> None:
246246
"""
247247
Push a tag to remote repository.
248248
249249
Args:
250250
tag_name: Name of the tag to push
251251
remote: Remote name (default: "origin")
252+
force: Whether to force push the tag (default: False)
252253
"""
253-
self.repo.git.push(remote, tag_name)
254+
if force:
255+
self.repo.git.push(remote, tag_name, "--force")
256+
else:
257+
self.repo.git.push(remote, tag_name)
254258

255259
def tag_exists(self, tag_name: str, remote: bool = False) -> bool:
256260
"""

0 commit comments

Comments
 (0)