Skip to content

Commit

Permalink
fix: sort keys in __MISE_DIFF to make the serialised value determin…
Browse files Browse the repository at this point in the history
…istic (jdx#3640)

Co-authored-by: jdx <216188+jdx@users.noreply.github.com>
  • Loading branch information
2 people authored and miguelmig committed Dec 21, 2024
1 parent 326e34f commit f0125a5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/env_diff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
use std::ffi::OsString;
use std::fmt::Debug;
use std::io::prelude::*;
Expand All @@ -8,6 +8,7 @@ use base64::prelude::*;
use eyre::Result;
use flate2::write::{ZlibDecoder, ZlibEncoder};
use flate2::Compression;
use indexmap::IndexMap;
use itertools::Itertools;
use serde_derive::{Deserialize, Serialize};

Expand All @@ -17,9 +18,9 @@ use crate::{cmd, file};
#[derive(Default, Serialize, Deserialize)]
pub struct EnvDiff {
#[serde(default)]
pub old: HashMap<String, String>,
pub old: IndexMap<String, String>,
#[serde(default)]
pub new: HashMap<String, String>,
pub new: IndexMap<String, String>,
#[serde(default)]
pub path: Vec<PathBuf>,
}
Expand Down Expand Up @@ -65,7 +66,7 @@ impl EnvDiff {
U: Into<OsString>,
V: Into<OsString>,
{
let env: HashMap<OsString, OsString> =
let env: IndexMap<OsString, OsString> =
env.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
let bash_path = file::which("bash").unwrap_or("/bin/bash".into());
let out = cmd!(
Expand Down Expand Up @@ -186,7 +187,7 @@ fn valid_key(k: &str) -> bool {

impl Debug for EnvDiff {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let print_sorted = |hashmap: &HashMap<String, String>| {
let print_sorted = |hashmap: &IndexMap<String, String>| {
hashmap
.iter()
.map(|(k, v)| format!("{k}={v}"))
Expand Down

0 comments on commit f0125a5

Please sign in to comment.