Skip to content

Commit

Permalink
feat: Give better info message for pixi global sync (#2100)
Browse files Browse the repository at this point in the history
It now informs you if `pixi global sync` did nothing
  • Loading branch information
Hofer-Julian authored Sep 20, 2024
1 parent 6358be9 commit e943408
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/cli/global/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@ pub struct Args {
pub async fn execute(args: Args) -> miette::Result<()> {
let config = Config::with_cli_config(&args.config);

global::sync(&config, args.assume_yes).await
let updated_env = global::sync(&config, args.assume_yes).await?;

if !updated_env {
eprintln!(
"{} Nothing to do. The pixi global installation is already up-to-date",
console::style(console::Emoji("✔ ", "")).green()
);
}

Ok(())
}
21 changes: 16 additions & 5 deletions src/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ pub(crate) fn prompt_user_to_continue(
Ok(true)
}

pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette::Error> {
// Syncs the manifest with the local environment
// Returns true if the global installation had to be updated
pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<bool, miette::Error> {
// Create directories
let bin_dir = BinDir::from_env().await?;
let env_root = EnvRoot::from_env().await?;
Expand Down Expand Up @@ -476,6 +478,8 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette
}
}

let mut updated_env = false;

for (env_name, parsed_environment) in project.environments() {
let specs = parsed_environment
.dependencies
Expand Down Expand Up @@ -505,8 +509,15 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette
.map(|r| r.repodata_record)
.collect_vec();

if !local_environment_matches_spec(repodata_records, &specs, parsed_environment.platform())
{
let install_env = !local_environment_matches_spec(
repodata_records,
&specs,
parsed_environment.platform(),
);

updated_env |= install_env;

if install_env {
install_environment(
&specs,
&parsed_environment,
Expand All @@ -518,7 +529,7 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette
.await?;
}

expose_executables(
updated_env |= expose_executables(
&env_name,
&parsed_environment,
specs.keys().cloned().collect(),
Expand All @@ -528,7 +539,7 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette
.await?;
}

Ok(())
Ok(updated_env)
}

/// Checks if the local environment matches the given specifications.
Expand Down

0 comments on commit e943408

Please sign in to comment.