Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/prek/src/cli/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) async fn auto_update(
store: &Store,
config: Option<PathBuf>,
filter_repos: Vec<String>,
exclude_repos: Vec<String>,
bleeding_edge: bool,
freeze: bool,
jobs: usize,
Expand All @@ -50,6 +51,10 @@ pub(crate) async fn auto_update(
remote_index: usize,
}

if bleeding_edge && exclude_repos.iter().any(|e| e == "*") {
anyhow::bail!("--bleeding-edge cannot be used with --exclude '*'");
}

let workspace_root = Workspace::find_root(config.as_deref(), &CWD)?;
// TODO: support selectors?
let selectors = Selectors::default();
Expand Down Expand Up @@ -93,6 +98,17 @@ pub(crate) async fn auto_update(
let reporter = AutoUpdateReporter::new(printer);

let mut tasks = futures::stream::iter(repo_updates.iter().filter(|(remote_repo, _)| {
// Skip pinned repositories
if remote_repo.pin == Some(true) {
return false;
}
// Exclude user specified repositories
if !exclude_repos.is_empty() {
let repo_url = remote_repo.repo.as_str();
return !exclude_repos
.iter()
.any(|e| e == "*" || repo_url.contains(e.as_str()));
}
// Filter by user specified repositories
if filter_repos.is_empty() {
true
Expand Down
7 changes: 6 additions & 1 deletion crates/prek/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,13 @@ pub(crate) struct AutoUpdateArgs {
#[arg(long)]
pub(crate) freeze: bool,
/// Only update this repository. This option may be specified multiple times.
#[arg(long)]
#[arg(long, conflicts_with = "exclude")]
pub(crate) repo: Vec<String>,
/// Exclude a repository from the update check. The value is matched as a
/// substring against the repo URL. Can be specified multiple times.
/// Use '*' to exclude all repositories.
#[arg(short, long, conflicts_with = "repo")]
pub(crate) exclude: Vec<String>,
/// Do not write changes to the config file, only display what would be changed.
#[arg(long)]
pub(crate) dry_run: bool,
Expand Down
9 changes: 9 additions & 0 deletions crates/prek/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,9 @@ pub(crate) struct RemoteRepo {
#[cfg_attr(feature = "schemars", schemars(schema_with = "schema_repo_remote"))]
pub repo: String,
pub rev: String,
/// Pin the repository at its current revision, skipping it during `auto-update`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pin: Option<bool>,
#[serde(skip_serializing)]
pub hooks: Vec<RemoteHook>,

Expand All @@ -862,6 +865,7 @@ impl RemoteRepo {
Self {
repo,
rev,
pin: None,
hooks,
_unused_keys: BTreeMap::new(),
}
Expand Down Expand Up @@ -969,6 +973,7 @@ impl<'de> Deserialize<'de> for Repo {

let mut repo: Option<String> = None;
let mut rev: Option<String> = None;
let mut pin: Option<bool> = None;
let mut hooks: Option<HooksValue> = None;
let mut unused = BTreeMap::new();

Expand All @@ -981,6 +986,9 @@ impl<'de> Deserialize<'de> for Repo {
"rev" => {
rev = Some(map.next_value()?);
}
"pin" => {
pin = Some(map.next_value()?);
}
"hooks" => {
hooks = Some(match repo.as_deref() {
Some("local") => HooksValue::Local(map.next_value()?),
Expand Down Expand Up @@ -1070,6 +1078,7 @@ impl<'de> Deserialize<'de> for Repo {
Ok(Repo::Remote(RemoteRepo {
repo: repo_value,
rev,
pin,
hooks,
_unused_keys: unused,
}))
Expand Down
1 change: 1 addition & 0 deletions crates/prek/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
&store,
cli.globals.config,
args.repo,
args.exclude,
args.bleeding_edge,
args.freeze,
args.jobs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Config {
RemoteRepo {
repo: "https://github.com/pre-commit/mirrors-mypy",
rev: "1.0",
pin: None,
hooks: [
RemoteHook {
id: "mypy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Config {
RemoteRepo {
repo: "https://github.com/crate-ci/typos",
rev: "v1.0.0",
pin: None,
hooks: [
RemoteHook {
id: "typos",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Config {
RemoteRepo {
repo: "https://github.com/crate-ci/typos",
rev: "v1.0.0",
pin: None,
hooks: [
RemoteHook {
id: "typos",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Config {
RemoteRepo {
repo: "https://github.com/pre-commit/pre-commit-hooks",
rev: "v6.0.0",
pin: None,
hooks: [
RemoteHook {
id: "trailing-whitespace",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Config {
RemoteRepo {
repo: "https://github.com/abravalheri/validate-pyproject",
rev: "v0.20.2",
pin: None,
hooks: [
RemoteHook {
id: "validate-pyproject",
Expand Down Expand Up @@ -46,6 +47,7 @@ Config {
RemoteRepo {
repo: "https://github.com/crate-ci/typos",
rev: "v1.26.0",
pin: None,
hooks: [
RemoteHook {
id: "typos",
Expand Down Expand Up @@ -176,6 +178,7 @@ Config {
RemoteRepo {
repo: "https://github.com/pre-commit/mirrors-prettier",
rev: "v3.1.0",
pin: None,
hooks: [
RemoteHook {
id: "prettier",
Expand Down Expand Up @@ -219,6 +222,7 @@ Config {
RemoteRepo {
repo: "https://github.com/astral-sh/ruff-pre-commit",
rev: "v0.6.9",
pin: None,
hooks: [
RemoteHook {
id: "ruff-format",
Expand Down
Loading
Loading