@@ -189,21 +189,22 @@ fn git(
189189 // - untracked files (which are "new" worktree files)
190190 // - ignored (in case the user has an `include` directive that
191191 // conflicts with .gitignore).
192- let mut dirty_files = Vec :: new ( ) ;
192+ let ( mut dirty_files, mut dirty_files_outside_package_root ) = ( Vec :: new ( ) , Vec :: new ( ) ) ;
193193 let workdir = repo. workdir ( ) . unwrap ( ) ;
194- let mut dirty_files_outside_of_package_root = collect_statuses (
194+ collect_statuses (
195195 repo,
196196 workdir,
197197 relative_package_root ( repo, pkg. root ( ) ) . as_deref ( ) ,
198198 & mut dirty_files,
199+ & mut dirty_files_outside_package_root,
199200 ) ?;
200201
201202 // Include each submodule so that the error message can provide
202203 // specifically *which* files in a submodule are modified.
203204 status_submodules (
204205 repo,
205206 & mut dirty_files,
206- & mut dirty_files_outside_of_package_root ,
207+ & mut dirty_files_outside_package_root ,
207208 ) ?;
208209
209210 // Find the intersection of dirty in git, and the src_files that would
@@ -230,7 +231,7 @@ fn git(
230231 } )
231232 . map ( |p| p. as_ref ( ) )
232233 . chain (
233- dirty_files_outside_pkg_root ( ws, pkg, & dirty_files_outside_of_package_root , src_files) ?
234+ dirty_files_outside_pkg_root ( ws, pkg, & dirty_files_outside_package_root , src_files) ?
234235 . iter ( ) ,
235236 )
236237 . map ( |path| {
@@ -243,8 +244,6 @@ fn git(
243244 . collect ( ) ;
244245 let dirty = !dirty_src_files. is_empty ( ) ;
245246 if !dirty || opts. allow_dirty {
246- // Must check whether the repo has no commit firstly; otherwise `revparse_single` would fail on bare commit repo.
247- // Due to lacking the `sha1` field, it's better not record the `GitVcsInfo` for consistency.
248247 let maybe_head_id = repo. head ( ) ?. try_peel_to_id_in_place ( ) ?;
249248 Ok ( maybe_head_id. map ( |id| GitVcsInfo {
250249 sha1 : id. to_string ( ) ,
@@ -264,14 +263,16 @@ fn git(
264263
265264/// Helper to collect dirty statuses for a single repo.
266265/// `relative_package_root` is `Some` if the root is a sub-directory of the workdir.
267- /// Returns the dirty files outside `relative_package_root`.
266+ /// Writes dirty files outside `relative_package_root` into `dirty_files_outside_package_root`,
267+ /// and all *everything else* into `dirty_files`.
268268#[ must_use]
269269fn collect_statuses (
270270 repo : & gix:: Repository ,
271271 workdir : & Path ,
272272 relative_package_root : Option < & Path > ,
273273 dirty_files : & mut Vec < PathBuf > ,
274- ) -> CargoResult < Vec < PathBuf > > {
274+ dirty_files_outside_package_root : & mut Vec < PathBuf > ,
275+ ) -> CargoResult < ( ) > {
275276 let statuses = repo
276277 . status ( gix:: progress:: Discard ) ?
277278 . dirwalk_options ( |opts| {
@@ -296,7 +297,6 @@ fn collect_statuses(
296297 )
297298 } ) ?;
298299
299- let mut dirty_files_outside_of_package_root = Vec :: new ( ) ;
300300 for status in statuses {
301301 let status = status. with_context ( || {
302302 format ! (
@@ -308,7 +308,7 @@ fn collect_statuses(
308308 let rel_path = gix:: path:: from_bstr ( status. location ( ) ) ;
309309 let path = workdir. join ( & rel_path) ;
310310 if relative_package_root. is_some_and ( |pkg_root| !rel_path. starts_with ( pkg_root) ) {
311- dirty_files_outside_of_package_root . push ( path) ;
311+ dirty_files_outside_package_root . push ( path) ;
312312 continue ;
313313 }
314314
@@ -326,14 +326,14 @@ fn collect_statuses(
326326
327327 dirty_files. push ( path) ;
328328 }
329- Ok ( dirty_files_outside_of_package_root )
329+ Ok ( ( ) )
330330}
331331
332332/// Helper to collect dirty statuses while recursing into submodules.
333333fn status_submodules (
334334 repo : & gix:: Repository ,
335335 dirty_files : & mut Vec < PathBuf > ,
336- dirty_files_outside_of_package_root : & mut Vec < PathBuf > ,
336+ dirty_files_outside_package_root : & mut Vec < PathBuf > ,
337337) -> CargoResult < ( ) > {
338338 let Some ( submodules) = repo. submodules ( ) ? else {
339339 return Ok ( ( ) ) ;
@@ -345,13 +345,14 @@ fn status_submodules(
345345 let Some ( workdir) = sub_repo. workdir ( ) else {
346346 continue ;
347347 } ;
348- status_submodules ( & sub_repo, dirty_files, dirty_files_outside_of_package_root ) ?;
349- dirty_files_outside_of_package_root . extend ( collect_statuses (
348+ status_submodules ( & sub_repo, dirty_files, dirty_files_outside_package_root ) ?;
349+ collect_statuses (
350350 & sub_repo,
351351 workdir,
352352 None ,
353353 dirty_files,
354- ) ?) ;
354+ dirty_files_outside_package_root,
355+ ) ?;
355356 }
356357 }
357358 Ok ( ( ) )
0 commit comments