Skip to content

Commit 9fa8e3c

Browse files
committed
Add failing test for issue #46: Git tag update regression
This test demonstrates that updating from one Git tag to another fails in v4.x (worked in v2.x). Steps the test follows: 1. Create a repo with content at tag 1.0.0 2. Add more content and create tag 2.0.0 3. Initial checkout with branch=1.0.0 (works) 4. Update config to branch=2.0.0 5. Run update (FAILS - exits with 'No such branch 2.0.0') The test currently fails because git_update() treats tags as branches, trying to find them in 'git branch -a' output where they don't appear. Related to #46
1 parent c9ba1ae commit 9fa8e3c

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/test_git.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,60 @@ def test_update_verbose(mkgitrepo, src, capsys):
202202
assert "Already up to date" in captured.out.replace("-", " ")
203203
status = vcs_status(sources, verbose=True)
204204
assert status == {"egg": ("clean", "## master...origin/master\n")}
205+
206+
207+
def test_update_git_tag_to_new_tag(mkgitrepo, src):
208+
"""Test that updating from one git tag to another works correctly.
209+
210+
This test reproduces issue #46: changing the branch option from one tag
211+
to another tag should update the checkout to the new tag.
212+
213+
Regression in v4.x - worked in v2.x
214+
"""
215+
repository = mkgitrepo("repository")
216+
# Create initial content and tag it as 1.0.0
217+
repository.add_file("foo", msg="Initial")
218+
repository("git tag 1.0.0", echo=False)
219+
220+
# Create more content and tag as 2.0.0
221+
repository.add_file("bar", msg="Second")
222+
repository("git tag 2.0.0", echo=False)
223+
224+
path = src / "egg"
225+
226+
# Initial checkout with tag 1.0.0
227+
sources = {
228+
"egg": dict(
229+
vcs="git",
230+
name="egg",
231+
branch="1.0.0", # This is actually a tag, not a branch
232+
url=str(repository.base),
233+
path=str(path),
234+
)
235+
}
236+
packages = ["egg"]
237+
verbose = False
238+
239+
# Checkout at tag 1.0.0
240+
vcs_checkout(sources, packages, verbose)
241+
assert {x for x in path.iterdir()} == {path / ".git", path / "foo"}
242+
243+
# Verify we're at tag 1.0.0
244+
result = repository.process.check_call(f"git -C {path} describe --tags", echo=False)
245+
current_tag = result[0].decode("utf8").strip()
246+
assert current_tag == "1.0.0"
247+
248+
# Now update the sources to use tag 2.0.0
249+
sources["egg"]["branch"] = "2.0.0"
250+
251+
# Update should switch to tag 2.0.0
252+
# BUG: This will fail because the code treats tags as branches
253+
vcs_update(sources, packages, verbose)
254+
255+
# After update, we should have both foo and bar (tag 2.0.0)
256+
assert {x for x in path.iterdir()} == {path / ".git", path / "foo", path / "bar"}
257+
258+
# Verify we're now at tag 2.0.0
259+
result = repository.process.check_call(f"git -C {path} describe --tags", echo=False)
260+
current_tag = result[0].decode("utf8").strip()
261+
assert current_tag == "2.0.0"

0 commit comments

Comments
 (0)