Skip to content

Fix update/revert loop when .luca-version is present#59

Merged
albertodebortoli merged 2 commits intomainfrom
fix-update-luca-version-sync
Apr 10, 2026
Merged

Fix update/revert loop when .luca-version is present#59
albertodebortoli merged 2 commits intomainfrom
fix-update-luca-version-sync

Conversation

@albertodebortoli
Copy link
Copy Markdown
Member

Description

When a project pins a Luca version via .luca-version, running luca update would trigger two consecutive updates:

  1. The updateIfNeeded pre-flight (runs before every command) sees the pin and installs it (e.g. 0.12.0)
  2. The update command itself fetches the latest release and installs that (e.g. 0.13.0), overwriting what was just installed

On the next run of any command, updateIfNeeded would see the stale pin again and downgrade back to 0.12.0. Running luca update again would repeat the cycle — creating an update/revert loop across repeated invocations.

This PR fixes the issue in two ways:

  • Skip updateIfNeeded when the command is update: since the update command fetches the latest release itself, running the pre-flight check is redundant and wasteful.
  • Sync .luca-version after a successful update: after updateToLatest installs a new version, write it back into .luca-version (only when the file already exists) so the pin stays in sync and updateIfNeeded won't attempt to downgrade on the next run.

Type of Change

  • Feature

How Has This Been Tested?

  • Added / updated unit tests

Three new tests covering .luca-version sync after updateToLatest:

  • test_updateToLatest_versionFileExists_updatesVersionFile.luca-version is written with the new version
  • test_updateToLatest_noVersionFile_doesNotCreateOne — no file created when there's no existing pin
  • test_updateToLatest_alreadyUpToDate_doesNotWriteVersionFile — no write when already at latest

Checklist

  • Swift code builds locally (swift build)
  • Tests pass locally (swift test)
  • Code style / formatting respected

Breaking Changes?

  • No

Before this fix, `updateToLatest` would install the latest GitHub
release but leave `.luca-version` unchanged. On the next invocation
`updateIfNeeded` (which runs before every command) would see the
stale pin, downgrade back to the pinned version, and a subsequent
`luca update` would upgrade again — creating an update/revert loop
across repeated runs. Write the newly installed version into
`.luca-version` when the file already exists so the pin stays in
sync. When no `.luca-version` is present, behaviour is unchanged.
The update command fetches the latest release itself, so running
updateIfNeeded beforehand is wasteful — it would install the
.luca-version pin only for updateToLatest to overwrite it moments
later. After the update, write the new version into .luca-version
(when the file exists) so the pin stays in sync.

Before this fix, running luca update with a .luca-version pin
older than the latest release would produce two consecutive
downloads: first updateIfNeeded would install the pinned version,
then updateToLatest would install the latest, effectively updating
and reverting in a loop across repeated runs.
@albertodebortoli albertodebortoli added this to the 0.14.0 milestone Apr 10, 2026
@albertodebortoli albertodebortoli added feature New feature or enhancement bugfix Something isn't working and removed feature New feature or enhancement labels Apr 10, 2026
@albertodebortoli albertodebortoli marked this pull request as ready for review April 10, 2026 13:12
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@albertodebortoli albertodebortoli merged commit b2c729c into main Apr 10, 2026
3 checks passed
@albertodebortoli albertodebortoli deleted the fix-update-luca-version-sync branch April 10, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant