Skip to content

Commit

Permalink
Merge pull request #1807 from timbrel/fix-deleting-remote-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Nov 19, 2023
2 parents e8ff1a6 + 6a5babc commit f8be448
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions core/interfaces/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re

import sublime
from sublime_plugin import WindowCommand

from ..commands import GsNavigate
Expand Down Expand Up @@ -217,7 +218,7 @@ def render_local_tags(self, local_tags, max_items):

remote_tags, remote_tag_names = set(), set()
# wait until all settled to prohibit intermediate state to be drawn
# what we draw explcitily relies on *all* known remote tags
# what we draw explicitly relies on *all* known remote tags
if all(info["state"] != "loading" for info in self.state["remote_tags"].values()):
for info in self.state["remote_tags"].values():
if info["state"] == "succeeded":
Expand Down Expand Up @@ -403,44 +404,41 @@ class gs_tags_delete(TagsInterfaceCommand):

@on_worker
def run(self, edit):
interface = self.interface
self.delete_local(interface)
self.delete_remote(interface)
util.view.refresh_gitsavvy(self.view)

def delete_local(self, interface):
# type: (sublime.Edit) -> None
local_tags = self.delete_local()
remote_tags = self.delete_remote()
if local_tags or remote_tags:
flash(self.view, TAG_DELETE_MESSAGE)
if remote_tags:
self.interface.state["remote_tags"] = {}
util.view.refresh_gitsavvy(self.view)

def delete_local(self):
# type: () -> List[str]
tags_to_delete = self.selected_local_tags()
if not tags_to_delete:
return

for tag in tags_to_delete:
rv = self.git("tag", "-d", tag)
match = EXTRACT_COMMIT.search(rv.strip())
if match:
commit = match.group(1)
uprint(DELETE_UNDO_MESSAGE.format(tag, commit))

flash(self.view, TAG_DELETE_MESSAGE)
util.view.refresh_gitsavvy(self.view)
return tags_to_delete

def delete_remote(self, interface):
if not interface.remotes:
return

for remote_name, remote in interface.remotes.items():
def delete_remote(self):
# type: () -> List[str]
all_deleted_tags = []
for remote_name in self.interface.state["remotes"]:
tags_to_delete = self.selected_remote_tags(remote_name)

all_deleted_tags += tags_to_delete
if tags_to_delete:
self.git(
"push",
remote_name,
"--delete",
*("refs/tags/" + tag for tag in tags_to_delete)
)

flash(self.view, TAG_DELETE_MESSAGE)
interface.remotes = None
util.view.refresh_gitsavvy(self.view)
return all_deleted_tags


class gs_tags_push(TagsInterfaceCommand):
Expand Down

0 comments on commit f8be448

Please sign in to comment.