Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding deletion for old tag references #845

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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