Skip to content

Use semver fallback sort when tag timestamps are equal#1579

Merged
j178 merged 3 commits intoj178:masterfrom
shaanmajid:fix/autoupdate-equal-timestamp
Feb 6, 2026
Merged

Use semver fallback sort when tag timestamps are equal#1579
j178 merged 3 commits intoj178:masterfrom
shaanmajid:fix/autoupdate-equal-timestamp

Conversation

@shaanmajid
Copy link
Collaborator

@shaanmajid shaanmajid commented Feb 6, 2026

Fixes #1533

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 97.29730% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.66%. Comparing base (4ff825e) to head (c26bdb2).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/cli/auto_update.rs 97.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1579      +/-   ##
==========================================
+ Coverage   91.58%   91.66%   +0.08%     
==========================================
  Files          92       93       +1     
  Lines       18136    18312     +176     
==========================================
+ Hits        16610    16786     +176     
  Misses       1526     1526              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shaanmajid shaanmajid changed the title Fix/autoupdate equal timestamp fix(auto-update): use semver fallback sort when tag timestamps are equal Feb 6, 2026
@shaanmajid shaanmajid marked this pull request as ready for review February 6, 2026 02:58
@shaanmajid shaanmajid requested a review from j178 as a code owner February 6, 2026 02:58
@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 6, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.42% (23.6 MiB → 23.7 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 80.9KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 71.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.2KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 38.4KiB              prek prek::run::{{closure}}
 0.1%   0.3% 31.7KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.4KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.3% 28.3KiB              prek prek::identify::by_extension::{{closure}}
 0.1%   0.2% 24.8KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.6KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.1KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 22.1KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.2KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.5KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.2KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
38.4%  91.6%  9.1MiB                   And 20941 smaller methods. Use -n N to show more.
41.9% 100.0%  9.9MiB                   .text section size, the file size is 23.7MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 73.5KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 71.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.5KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 38.1KiB              prek prek::run::{{closure}}
 0.1%   0.3% 32.0KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.4KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.3% 28.3KiB              prek prek::identify::by_extension::{{closure}}
 0.1%   0.2% 24.9KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.6KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.2KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.2KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.6KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.5KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.5KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.2KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
38.3%  91.6%  9.1MiB                   And 20911 smaller methods. Use -n N to show more.
41.9% 100.0%  9.9MiB                   .text section size, the file size is 23.6MiB

@shaanmajid shaanmajid force-pushed the fix/autoupdate-equal-timestamp branch from 0e0b906 to ace89aa Compare February 6, 2026 03:05
@shaanmajid
Copy link
Collaborator Author

It does feel a bit gross to have to extract SemVer logic here, but it seems both appropriate and necessary as a way of resolving the issue.

When all tags share the same creation timestamp (common in mirror
repos), the previous sort order was non-deterministic and could
select an older version. Add a stable secondary sort that prefers
higher semver versions within equal-timestamp groups.

Fixes j178#1533
- Remove redundant `git config` calls from `create_local_git_repo`;
  `git_cmd()` already passes these via `-c` flags on every invocation.
- Extract `create_repo_inner` with `increment_timestamps` flag and add
  `create_local_git_repo_fixed_ts` for equal-timestamp test scenarios.
- Simplify `auto_update_equal_timestamp_tags_picks_highest_version` to
  use the new helper instead of 110 lines of manual repo setup.
- Add test for mixed semver/non-semver tags at equal timestamps
  (exercises the Ok/Err match arms in the sort comparator).
- Add test for mixed timestamp groups with equal-timestamp subgroups
  (validates primary timestamp sort is preserved with semver tiebreaker).
@shaanmajid shaanmajid force-pushed the fix/autoupdate-equal-timestamp branch from ace89aa to 2eb1774 Compare February 6, 2026 03:23
@j178
Copy link
Owner

j178 commented Feb 6, 2026

(The color test failure is a known flaky test)

@j178 j178 added the bug Something isn't working label Feb 6, 2026
j178
j178 previously approved these changes Feb 6, 2026
Copy link
Owner

@j178 j178 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@j178

This comment was marked as resolved.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes prek auto-update incorrectly rolling back to older tags in mirror repositories when multiple tags share the same timestamp (as in issue #1533), by adding a semver-based tie-breaker when timestamps are equal.

Changes:

  • Add semver-aware ordering for equal-timestamp tag groups during auto-update tag selection.
  • Add integration tests covering equal-timestamp semver selection, semver-vs-nonsemver preference, and mixed timestamp groups.
  • Add a unit test to validate the equal-timestamp ordering behavior in get_tag_timestamps.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/prek/src/cli/auto_update.rs Adds semver-based sorting within equal-timestamp tag groups and a unit test for the behavior.
crates/prek/tests/auto_update.rs Adds integration tests and helper support for constructing repos with equal timestamps to reproduce/guard against the rollback scenario.

@j178 j178 changed the title fix(auto-update): use semver fallback sort when tag timestamps are equal Use semver fallback sort when tag timestamps are equal Feb 6, 2026
@j178 j178 merged commit 9172278 into j178:master Feb 6, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prek autoupdate rollbacks csslint from 1.0.5 to 1.0.0

2 participants