Sort lockfile entries by name
Selective updates appended to the end, causing unnecessary diffs.

Assisted-by: Claude Opus 4.6 via pi
change mrqkonkxmztprntmnpouzsyylmznxzuk
commit 547b815a1157c632c00f32305fb0e56963af00bf
author Alpha Chen <alpha@kejadlen.dev>
date
parent pwqvlkzn
diff --git a/src/lockfile.rs b/src/lockfile.rs
index 10aec1f..e22312e 100644
--- a/src/lockfile.rs
+++ b/src/lockfile.rs
@@ -1,13 +1,13 @@
 use color_eyre::eyre::{Context, Result};
 use serde::{Deserialize, Serialize};
 
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
 pub struct Lockfile {
     #[serde(default)]
     pub plugins: Vec<LockedPlugin>,
 }
 
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
 pub struct LockedPlugin {
     pub name: String,
     pub src: String,
@@ -30,7 +30,9 @@ pub fn save(lockfile: &Lockfile) -> Result<()> {
         std::fs::create_dir_all(parent)
             .with_context(|| format!("failed to create data dir: {}", parent.display()))?;
     }
-    let contents = serde_yml::to_string(lockfile).context("failed to serialize lockfile")?;
+    let mut sorted = lockfile.clone();
+    sorted.plugins.sort_by(|a, b| a.name.cmp(&b.name));
+    let contents = serde_yml::to_string(&sorted).context("failed to serialize lockfile")?;
     std::fs::write(&path, contents)
         .with_context(|| format!("failed to write lockfile: {}", path.display()))?;
     Ok(())