@@ -189,21 +189,22 @@ fn git(
189
189
// - untracked files (which are "new" worktree files)
190
190
// - ignored (in case the user has an `include` directive that
191
191
// 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 ( ) ) ;
193
193
let workdir = repo. workdir ( ) . unwrap ( ) ;
194
- let mut dirty_files_outside_of_package_root = collect_statuses (
194
+ collect_statuses (
195
195
repo,
196
196
workdir,
197
197
relative_package_root ( repo, pkg. root ( ) ) . as_deref ( ) ,
198
198
& mut dirty_files,
199
+ & mut dirty_files_outside_package_root,
199
200
) ?;
200
201
201
202
// Include each submodule so that the error message can provide
202
203
// specifically *which* files in a submodule are modified.
203
204
status_submodules (
204
205
repo,
205
206
& mut dirty_files,
206
- & mut dirty_files_outside_of_package_root ,
207
+ & mut dirty_files_outside_package_root ,
207
208
) ?;
208
209
209
210
// Find the intersection of dirty in git, and the src_files that would
@@ -230,7 +231,7 @@ fn git(
230
231
} )
231
232
. map ( |p| p. as_ref ( ) )
232
233
. 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) ?
234
235
. iter ( ) ,
235
236
)
236
237
. map ( |path| {
@@ -243,8 +244,6 @@ fn git(
243
244
. collect ( ) ;
244
245
let dirty = !dirty_src_files. is_empty ( ) ;
245
246
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.
248
247
let maybe_head_id = repo. head ( ) ?. try_peel_to_id_in_place ( ) ?;
249
248
Ok ( maybe_head_id. map ( |id| GitVcsInfo {
250
249
sha1 : id. to_string ( ) ,
@@ -264,14 +263,16 @@ fn git(
264
263
265
264
/// Helper to collect dirty statuses for a single repo.
266
265
/// `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`.
268
268
#[ must_use]
269
269
fn collect_statuses (
270
270
repo : & gix:: Repository ,
271
271
workdir : & Path ,
272
272
relative_package_root : Option < & Path > ,
273
273
dirty_files : & mut Vec < PathBuf > ,
274
- ) -> CargoResult < Vec < PathBuf > > {
274
+ dirty_files_outside_package_root : & mut Vec < PathBuf > ,
275
+ ) -> CargoResult < ( ) > {
275
276
let statuses = repo
276
277
. status ( gix:: progress:: Discard ) ?
277
278
. dirwalk_options ( |opts| {
@@ -296,7 +297,6 @@ fn collect_statuses(
296
297
)
297
298
} ) ?;
298
299
299
- let mut dirty_files_outside_of_package_root = Vec :: new ( ) ;
300
300
for status in statuses {
301
301
let status = status. with_context ( || {
302
302
format ! (
@@ -308,7 +308,7 @@ fn collect_statuses(
308
308
let rel_path = gix:: path:: from_bstr ( status. location ( ) ) ;
309
309
let path = workdir. join ( & rel_path) ;
310
310
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) ;
312
312
continue ;
313
313
}
314
314
@@ -326,14 +326,14 @@ fn collect_statuses(
326
326
327
327
dirty_files. push ( path) ;
328
328
}
329
- Ok ( dirty_files_outside_of_package_root )
329
+ Ok ( ( ) )
330
330
}
331
331
332
332
/// Helper to collect dirty statuses while recursing into submodules.
333
333
fn status_submodules (
334
334
repo : & gix:: Repository ,
335
335
dirty_files : & mut Vec < PathBuf > ,
336
- dirty_files_outside_of_package_root : & mut Vec < PathBuf > ,
336
+ dirty_files_outside_package_root : & mut Vec < PathBuf > ,
337
337
) -> CargoResult < ( ) > {
338
338
let Some ( submodules) = repo. submodules ( ) ? else {
339
339
return Ok ( ( ) ) ;
@@ -345,13 +345,14 @@ fn status_submodules(
345
345
let Some ( workdir) = sub_repo. workdir ( ) else {
346
346
continue ;
347
347
} ;
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 (
350
350
& sub_repo,
351
351
workdir,
352
352
None ,
353
353
dirty_files,
354
- ) ?) ;
354
+ dirty_files_outside_package_root,
355
+ ) ?;
355
356
}
356
357
}
357
358
Ok ( ( ) )
0 commit comments