Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rceval'

Merges #845
Closes #845
  • Loading branch information
sduenas authored Aug 21, 2024
2 parents f0494d2 + 713b99d commit 5eb31be
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 <[email protected]>
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 5eb31be

Please sign in to comment.