Skip to content

Detect install source for actionable upgrade hints#1540

Merged
j178 merged 2 commits intoj178:masterfrom
shaanmajid:feat/install-source-detection
Feb 3, 2026
Merged

Detect install source for actionable upgrade hints#1540
j178 merged 2 commits intoj178:masterfrom
shaanmajid:feat/install-source-detection

Conversation

@shaanmajid
Copy link
Collaborator

@shaanmajid shaanmajid commented Feb 3, 2026

Detects how prek was installed (Homebrew or Cargo) by inspecting the executable path, then provides actionable upgrade hints when:

  • prek self update fails because prek wasn't installed via standalone scripts
  • minimum_prek_version isn't satisfied

Based largely on the approach uv implemented in astral-sh/uv#16838.

Detection heuristics:

  • Homebrew: path contains /Cellar/prek/
  • Cargo: path contains /.cargo/bin/

Example output:

error: prek was installed via an external package manager and cannot self-update.
hint: You installed prek via Homebrew. To update, run brew update && brew upgrade prek

See discussion in #1490 for further context.

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 71.79487% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.57%. Comparing base (f8df4e7) to head (e3c1be1).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/main.rs 0.00% 12 Missing ⚠️
crates/prek/src/install_source.rs 83.87% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1540      +/-   ##
==========================================
- Coverage   91.65%   91.57%   -0.09%     
==========================================
  Files          90       91       +1     
  Lines       17813    17892      +79     
==========================================
+ Hits        16326    16384      +58     
- Misses       1487     1508      +21     

☔ 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.

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 3, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (23.2 MiB → 23.2 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 72.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7% 71.6KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 65.7KiB              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.8KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.9KiB              prek prek::run::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.7KiB              prek prek::cli::run::run::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% 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.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.9KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.7KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{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.3KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
37.8%  91.2%  8.8MiB                   And 20435 smaller methods. Use -n N to show more.
41.5% 100.0%  9.6MiB                   .text section size, the file size is 23.2MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 74.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.7% 65.7KiB              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.8KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 43.1KiB              prek prek::run::{{closure}}
 0.2%   0.4% 41.6KiB              prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 31.1KiB             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% 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.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.7KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 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.3KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
37.8%  91.2%  8.8MiB                   And 20451 smaller methods. Use -n N to show more.
41.5% 100.0%  9.6MiB                   .text section size, the file size is 23.2MiB

@shaanmajid shaanmajid added the enhancement New feature or request label Feb 3, 2026
@shaanmajid shaanmajid force-pushed the feat/install-source-detection branch 6 times, most recently from 670c059 to 6ddfb43 Compare February 3, 2026 04:35
Detects how prek was installed (Homebrew or Cargo) by inspecting the
executable path, then provides actionable upgrade hints when:

- `prek self update` fails (not installed via standalone scripts)
- `minimum_prek_version` isn't satisfied

Detection heuristics:
- Homebrew: path contains `/Cellar/prek/`
- Cargo: path contains `/.cargo/bin/`

Based on astral-sh/uv#16838.
@shaanmajid shaanmajid changed the title Feat/install source detection feat(ux): detect install source for actionable upgrade hints Feb 3, 2026
@shaanmajid shaanmajid marked this pull request as ready for review February 3, 2026 05:14
@shaanmajid shaanmajid requested a review from j178 as a code owner February 3, 2026 05:14
@shaanmajid shaanmajid force-pushed the feat/install-source-detection branch from 6ddfb43 to e1c0f2a Compare February 3, 2026 05:15
@j178 j178 changed the title feat(ux): detect install source for actionable upgrade hints Detect install source for actionable upgrade hints Feb 3, 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.

Thanks!

@j178 j178 merged commit d630b38 into j178:master Feb 3, 2026
49 checks passed
j178 added a commit that referenced this pull request Feb 3, 2026
Just realized that [`cargo-binstall`](https://github.com/cargo-bins/cargo-binstall) also installs things into `~/.cargo/bin`, so there’s no (easy) way to tell whether something was installed with `cargo install` or `cargo binstall`.

Partially reverts #1540
j178 added a commit that referenced this pull request Feb 3, 2026
Just realized that
[`cargo-binstall`](https://github.com/cargo-bins/cargo-binstall) also
installs things into `~/.cargo/bin`, so there’s no (easy) way to tell
whether something was installed with `cargo install` or `cargo
binstall`.

Partially reverts #1540
@shaanmajid shaanmajid deleted the feat/install-source-detection branch February 3, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants