Skip to content

Commit

Permalink
Adding deletion of old tag references
Browse files Browse the repository at this point in the history
Signed-off-by: mjgaughan <mgaughan@proton.me>

updating tag deletion to persist head deletion

Signed-off-by: mjgaughan <mgaughan@proton.me>

adding draft test for tag deletion

Signed-off-by: mjgaughan <mgaughan@proton.me>

linting tests per flake8 specifications

Signed-off-by: mjgaughan <mgaughan@proton.me>

Apply code review suggestions for test compliance

Co-authored-by: Venu Vardhan Reddy Tekula <venuvardhanreddytekula8@gmail.com>
Signed-off-by: mjgaughan <58380965+mjgaughan@users.noreply.github.com>

adding changelog

Adding upstream tag deletion to remote mirroring.
  • Loading branch information
mjgaughan committed Aug 15, 2024
1 parent dc87cfa commit 8fcd884
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion perceval/backends/core/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ def _update_references(self, refs):

# Delete old references
for old_ref in self._discover_refs():
if not old_ref.refname.startswith('refs/heads/'):
if not old_ref.refname.startswith('refs/heads/') and not old_ref.refname.startswith('refs/tags/'):
continue
if old_ref.refname in new_refs:
continue
Expand Down
6 changes: 6 additions & 0 deletions releases/unreleased/fix-issue-#782.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
title: 'Fix issue #782'
category: fixed
author: Matt Gaughan <mgaughan@proton.me>
issue: 782
notes: >
The issue was that perceval would not delete old tags from upstream references. This change deletes tags locally if tags are deleted upstream.
40 changes: 40 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,46 @@ def test_sync(self):
shutil.rmtree(editable_path)
shutil.rmtree(new_path)

def test_tag_removal_sync(self):
"""Test sync process for tag removal"""
origin_path = os.path.join(self.tmp_repo_path, 'gittest')
editable_path = os.path.join(self.tmp_path, 'editgit')
new_path = os.path.join(self.tmp_path, 'newgit')

shutil.copytree(origin_path, editable_path)

repo = GitRepository.clone(editable_path, new_path)
repo.sync()

# Add a tag 'v.0.0-lw' to the refs and check that it exists
cmd = ['git', 'tag', 'v.0.0-lw']
subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=editable_path, env={'LANG': 'C'})

new_commits = repo.sync()
self.assertEqual(len(new_commits), 0)

# Verify that the new tag 'v.0.0-lw' exists in the refs
refs = discover_refs(new_path)
self.assertIn('refs/tags/v.0.0-lw', refs)

# Delete the tag 'v.0.0-lw' and check that it has been deleted from refs
cmd = ['git', 'tag', '-d', 'v.0.0-lw']
subprocess.check_output(cmd, stderr=subprocess.STDOUT,
cwd=editable_path, env={'LANG': 'C'})

new_commits = repo.sync()
self.assertEqual(len(new_commits), 0)

# Verify that the tag 'v.0.0-lw' is no longer in the refs
refs = discover_refs(new_path)
self.assertNotIn('refs/tags/v.0.0-lw', refs)
self.assertIn('refs/heads/master', refs)

# Cleanup
shutil.rmtree(editable_path)
shutil.rmtree(new_path)

def test_sync_from_empty_repos(self):
"""Test sync process on empty repositories"""

Expand Down

0 comments on commit 8fcd884

Please sign in to comment.