-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix AssertionError when cloning at annotated tag #10719
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
Merged
+147
−2
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| import pytest | ||
|
|
||
| from dulwich.client import FetchPackResult | ||
| from dulwich.refs import HEADREF | ||
| from dulwich.refs import Ref | ||
| from dulwich.repo import Repo | ||
|
|
||
| from poetry.console.exceptions import PoetryRuntimeError | ||
|
|
@@ -290,3 +292,135 @@ def test_clone_existing_locked_tag(tmp_path: Path, temp_repo: TempRepoFixture) - | |
| f"Try again later or remove the {tag_ref_lock} manually" | ||
| " if you are sure no other process is holding it." | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.skip_git_mock | ||
| def test_clone_annotated_tag(tmp_path: Path) -> None: | ||
| """Test cloning at an annotated tag (issue #10658).""" | ||
| from dulwich import porcelain | ||
| from dulwich.objects import Commit | ||
|
|
||
| # Create a source repository with an annotated tag | ||
| source_path = tmp_path / "source-repo" | ||
| source_path.mkdir() | ||
| repo = Repo.init(str(source_path)) | ||
|
|
||
| # Create initial commit | ||
| test_file = source_path / "test.txt" | ||
| test_file.write_text("test content", encoding="utf-8") | ||
| porcelain.add(repo, str(test_file)) | ||
| expected_commit_sha = porcelain.commit( | ||
| repo, | ||
| message=b"Initial commit", | ||
| author=b"Test <[email protected]>", | ||
| committer=b"Test <[email protected]>", | ||
| ) | ||
|
|
||
| # Create an annotated tag | ||
| porcelain.tag_create( | ||
| repo, | ||
| tag=b"v1.0.0", | ||
| message=b"Release 1.0.0", | ||
| author=b"Test <[email protected]>", | ||
| annotated=True, | ||
| ) | ||
|
|
||
| # Clone at the annotated tag | ||
| source_root_dir = tmp_path / "clone-root" | ||
| source_root_dir.mkdir() | ||
| cloned_repo = Git.clone( | ||
| url=source_path.as_uri(), | ||
| source_root=source_root_dir, | ||
| name="clone-test", | ||
| tag="v1.0.0", | ||
| ) | ||
|
|
||
| # Verify HEAD points to a commit, not a tag object | ||
| head_sha = cloned_repo.refs[HEADREF] | ||
| head_obj = cloned_repo.object_store[head_sha] | ||
| assert isinstance(head_obj, Commit), ( | ||
| f"HEAD should point to a Commit, got {type(head_obj).__name__}" | ||
| ) | ||
| # Verify it's the correct commit | ||
| assert head_sha == expected_commit_sha, ( | ||
| f"HEAD should point to the expected commit {expected_commit_sha.hex()}, " | ||
| f"got {head_sha.hex()}" | ||
| ) | ||
|
|
||
| # Verify the clone succeeded and files are present | ||
| clone_dir = source_root_dir / "clone-test" | ||
| assert (clone_dir / ".git").is_dir() | ||
| assert (clone_dir / "test.txt").exists() | ||
| assert (clone_dir / "test.txt").read_text(encoding="utf-8") == "test content" | ||
|
|
||
|
|
||
| @pytest.mark.skip_git_mock | ||
| def test_clone_nested_annotated_tags(tmp_path: Path) -> None: | ||
| """Test cloning at a tag that points to another tag (nested tags).""" | ||
| from dulwich import porcelain | ||
| from dulwich.objects import Commit | ||
| from dulwich.objects import Tag | ||
|
|
||
| # Create a source repository with nested annotated tags | ||
| source_path = tmp_path / "source-repo" | ||
| source_path.mkdir() | ||
| repo = Repo.init(str(source_path)) | ||
|
|
||
| # Create initial commit | ||
| test_file = source_path / "test.txt" | ||
| test_file.write_text("nested tag test", encoding="utf-8") | ||
| porcelain.add(repo, paths=[b"test.txt"]) | ||
| commit_sha = porcelain.commit( | ||
| repo, | ||
| message=b"Initial commit", | ||
| committer=b"Test <[email protected]>", | ||
| author=b"Test <[email protected]>", | ||
| ) | ||
|
|
||
| # Create first annotated tag pointing to the commit | ||
| tag1 = Tag() | ||
| tag1.name = b"v1.0.0" | ||
| tag1.object = (Commit, commit_sha) | ||
| tag1.message = b"First tag" | ||
| tag1.tag_time = 1234567890 | ||
| tag1.tag_timezone = 0 | ||
| tag1.tagger = b"Test <[email protected]>" | ||
| repo.object_store.add_object(tag1) | ||
| repo.refs[Ref(b"refs/tags/v1.0.0")] = tag1.id | ||
|
|
||
| # Create second annotated tag pointing to the first tag | ||
| tag2 = Tag() | ||
| tag2.name = b"v1.0.0-release" | ||
| tag2.object = (Tag, tag1.id) | ||
| tag2.message = b"Second tag (points to first tag)" | ||
| tag2.tag_time = 1234567891 | ||
| tag2.tag_timezone = 0 | ||
| tag2.tagger = b"Test <[email protected]>" | ||
| repo.object_store.add_object(tag2) | ||
| repo.refs[Ref(b"refs/tags/v1.0.0-release")] = tag2.id | ||
|
|
||
| # Clone at the nested tag | ||
| source_root_dir = tmp_path / "clone-root" | ||
| source_root_dir.mkdir() | ||
| cloned_repo = Git.clone( | ||
| url=source_path.as_uri(), | ||
| source_root=source_root_dir, | ||
| name="clone-test", | ||
| tag="v1.0.0-release", | ||
| ) | ||
|
|
||
| # Verify HEAD points to a commit, not a tag object | ||
| head_sha = cloned_repo.refs[HEADREF] | ||
| head_obj = cloned_repo.object_store[head_sha] | ||
| assert isinstance(head_obj, Commit), ( | ||
| f"HEAD should point to a Commit (peeling nested tags), got {type(head_obj).__name__}" | ||
| ) | ||
|
|
||
| # Verify it's the correct commit | ||
| assert head_sha == commit_sha | ||
|
|
||
| # Verify the clone succeeded and files are present | ||
| clone_dir = source_root_dir / "clone-test" | ||
| assert (clone_dir / ".git").is_dir() | ||
| assert (clone_dir / "test.txt").exists() | ||
| assert (clone_dir / "test.txt").read_text(encoding="utf-8") == "nested tag test" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.