1- use anyhow:: Result ;
2- use std:: ffi:: OsString ;
1+ use anyhow:: { Result , bail } ;
2+ use std:: { ffi:: OsString , fs } ;
33
44use crate :: {
55 app,
6- utils:: { command:: ChainArgs as _, git} ,
6+ utils:: { command:: ChainArgs as _, git, paths } ,
77} ;
88
99/// Check the Rust code for errors
@@ -20,11 +20,16 @@ pub struct Cli {
2020 fix : bool ,
2121}
2222
23+ #[ derive( strum:: Display , strum:: AsRefStr , Clone , Copy , Debug ) ]
24+ #[ strum( serialize_all = "lowercase" ) ]
25+ enum Tool {
26+ Clippy ,
27+ Check ,
28+ }
29+
2330impl Cli {
2431 /// Build the argument vector for cargo invocation.
25- fn build_args ( & self ) -> Vec < OsString > {
26- let tool = if self . clippy { "clippy" } else { "check" } ;
27-
32+ fn build_args ( & self , tool : Tool ) -> Vec < OsString > {
2833 let pre_args = if self . fix {
2934 vec ! [ "--fix" ]
3035 } else {
@@ -47,14 +52,30 @@ impl Cli {
4752 ]
4853 } ;
4954
50- [ tool, "--workspace" , "--all-targets" ]
55+ [ tool. as_ref ( ) , "--workspace" , "--all-targets" ]
5156 . chain_args ( feature_args)
5257 . chain_args ( pre_args)
5358 . chain_args ( clippy_args)
5459 }
5560
5661 pub fn exec ( self ) -> Result < ( ) > {
57- app:: exec ( "cargo" , self . build_args ( ) , true ) ?;
62+ let lock_file = paths:: find_repo_root ( ) ?. join ( "Cargo.lock" ) ;
63+ let lock_before = fs:: read ( & lock_file) ?;
64+
65+ let tool = if self . clippy {
66+ Tool :: Clippy
67+ } else {
68+ Tool :: Check
69+ } ;
70+
71+ app:: exec ( "cargo" , self . build_args ( tool) , true ) ?;
72+
73+ let lock_after = fs:: read ( & lock_file) ?;
74+ if lock_before != lock_after {
75+ bail ! (
76+ "Cargo.lock was modified by `cargo {tool}`. Please commit the updated Cargo.lock."
77+ ) ;
78+ }
5879
5980 // If --fix was used, check for changes and commit them.
6081 if self . fix {
0 commit comments