Skip to content

Conversation

@jensens
Copy link
Member

@jensens jensens commented Oct 22, 2025

Summary

Fixes #46: Git tags in branch option are now correctly handled during updates

This PR fixes a regression introduced in v3.x/v4.x where updating from one Git tag to another stopped working. Tags were incorrectly treated as branches during the update process.

Current Status: Demonstrating the Bug

Failing Test

The first commit adds test_update_git_tag_to_new_tag() that demonstrates the issue:

Test scenario:

  1. Create repo with tag 1.0.0
  2. Initial checkout with branch = 1.0.0 (works via git clone -b)
  3. Update config to branch = 2.0.0
  4. Run update (FAILS)

Error:

SystemExit: 1
src/mxdev/vcs/git.py:226: in git_switch_branch
    self.output((logger.error, f"No such branch {branch}"))
    sys.exit(1)

Root Cause

In git_update() at lines 249-251:

elif "branch" in self.source:
    stdout, stderr = self.git_switch_branch(stdout, stderr)
    stdout, stderr = self.git_merge_rbranch(stdout, stderr)

This code assumes the value in branch is an actual Git branch. When it's a tag:

  1. git fetch runs successfully (fetches tags)
  2. git_switch_branch() looks for the tag in git branch -a output
  3. Doesn't find it (tags ≠ branches)
  4. Exits with error: "No such branch 2.0.0"

Why initial checkout works: git clone -b 8.0.0 recognizes tags and works
Why update fails: The update logic only looks in branch listings

Next Steps

  • Implement tag detection in git_update()
  • Add logic to handle tags separately from branches
  • Verify test passes
  • Run linting
  • Update CHANGES.md
  • Mark PR ready when CI is green

Test Plan

# Currently fails:
pytest tests/test_git.py::test_update_git_tag_to_new_tag -v

# After fix, should pass

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
Add git_is_tag() method to detect if a branch value is actually a tag,
and handle tags correctly during git_update():
- Tags are checked out directly with 'git checkout <tag>'
- Branches use the existing switch + merge logic
- Explicitly fetch tags with 'git fetch --tags'

This fixes the regression where updating from one tag to another
stopped working in v4.x (worked in v2.x).

The test now passes, demonstrating that tag updates work correctly.

Fixes #46
@jensens jensens marked this pull request as ready for review October 22, 2025 10:43
@jensens jensens merged commit f38a75d into main Oct 22, 2025
23 checks passed
@jensens jensens deleted the fix/46-git-tag-update-regression branch October 22, 2025 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Existing repositories are no longer updated if Git tag is changed

2 participants