Skip to content

Commit 23405aa

Browse files
committed
try to fix windows (#301)
1 parent df0b52e commit 23405aa

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

git-worktree/src/index.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use git_hash::oid;
2+
use std::io::ErrorKind::AlreadyExists;
23

34
use crate::{index, index::checkout::Collision};
45

@@ -87,6 +88,7 @@ pub fn checkout<Find>(
8788
where
8889
Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<git_object::BlobRef<'a>>,
8990
{
91+
use std::io::ErrorKind::AlreadyExists;
9092
let root = path.as_ref();
9193
let mut buf = Vec::new();
9294
let mut collisions = Vec::new();
@@ -100,9 +102,17 @@ where
100102
match res {
101103
Ok(()) => {}
102104
// TODO: use ::IsDirectory as well when stabilized instead of raw_os_error()
105+
#[cfg(windows)]
103106
Err(index::checkout::Error::Io(err))
104-
if err.kind() == std::io::ErrorKind::AlreadyExists || err.raw_os_error() == Some(21) =>
107+
if err.kind() == AlreadyExists || err.kind() == std::io::ErrorKind::PermissionDenied =>
105108
{
109+
collisions.push(Collision {
110+
path: entry_path.into(),
111+
error_kind: err.kind(),
112+
});
113+
}
114+
#[cfg(not(windows))]
115+
Err(index::checkout::Error::Io(err)) if err.kind() == AlreadyExists || err.raw_os_error() == Some(21) => {
106116
// We are here because a file existed or was blocked by a directory which shouldn't be possible unless
107117
// we are on a file insensitive file system.
108118
collisions.push(Collision {

git-worktree/tests/index/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,29 @@ mod checkout {
8383
let opts = opts_with_symlink(true);
8484
let (source_tree, destination, _index, outcome) =
8585
checkout_index_in_tmp_dir(opts, "make_ignorecase_collisions").unwrap();
86+
#[cfg(windows)]
87+
let error_kind = ErrorKind::PermissionDenied;
88+
#[cfg(not(windows))]
89+
let error_kind = ErrorKind::AlreadyExists;
8690

8791
assert_eq!(
8892
outcome.collisions,
8993
vec![
9094
Collision {
9195
path: "FILE_x".into(),
92-
error_kind: ErrorKind::AlreadyExists,
96+
error_kind,
9397
},
9498
Collision {
9599
path: "d".into(),
96-
error_kind: ErrorKind::AlreadyExists,
100+
error_kind,
97101
},
98102
Collision {
99103
path: "file_X".into(),
100-
error_kind: ErrorKind::AlreadyExists,
104+
error_kind,
101105
},
102106
Collision {
103107
path: "file_x".into(),
104-
error_kind: ErrorKind::AlreadyExists,
108+
error_kind,
105109
},
106110
],
107111
"these files couldn't be checked out"

0 commit comments

Comments
 (0)