Skip to content

Commit 4fb131d

Browse files
committed
fix: Replacing a directory with non-directory will not cause an error anymore (#1735).
1 parent ad6b9b6 commit 4fb131d

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

gix-status/src/index_as_worktree/function.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ impl<'index> State<'_, 'index> {
379379
}
380380
}
381381
Ok(metadata) => metadata,
382-
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(Some(Change::Removed.into())),
382+
Err(err) if matches!(err.kind(), io::ErrorKind::NotADirectory | io::ErrorKind::NotFound) => {
383+
return Ok(Some(Change::Removed.into()))
384+
}
383385
Err(err) => {
384386
return Err(err.into());
385387
}
Binary file not shown.

gix-status/tests/fixtures/status_many.sh

+8
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ cp -R changed-and-untracked changed-and-untracked-and-renamed
3939
echo change >> content-with-rewrite
4040

4141
)
42+
43+
cp -R changed-and-untracked replace-dir-with-file
44+
(cd replace-dir-with-file
45+
git checkout executable
46+
rm untracked
47+
rm -Rf dir/
48+
touch dir
49+
)

gix-status/tests/status/index_as_worktree.rs

+24
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,30 @@ fn removed() {
243243
);
244244
}
245245

246+
#[test]
247+
fn replace_dir_with_file() {
248+
let out = fixture_filtered_detailed(
249+
"status_many",
250+
"replace-dir-with-file",
251+
&[],
252+
&[
253+
(BStr::new(b"dir/content"), 0, status_removed()),
254+
(BStr::new(b"dir/content2"), 1, status_removed()),
255+
],
256+
|_| {},
257+
false,
258+
);
259+
assert_eq!(
260+
out,
261+
Outcome {
262+
entries_to_process: 4,
263+
entries_processed: 4,
264+
symlink_metadata_calls: 4,
265+
..Default::default()
266+
}
267+
);
268+
}
269+
246270
#[test]
247271
fn subomdule_nochange() {
248272
assert_eq!(

0 commit comments

Comments
 (0)