Skip to content

Commit fa653bc

Browse files
Eh2406alexcrichton
authored andcommitted
work around for windows path separator for is_path_ignored (#335)
* work around for windows path separator for is_path_ignored * use cfg!
1 parent 9adea3d commit fa653bc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/repo.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,13 @@ impl Repository {
20442044

20452045
/// Test if the ignore rules apply to a given path.
20462046
pub fn is_path_ignored<P: AsRef<Path>>(&self, path: P) -> Result<bool, Error> {
2047-
let path = try!(path.as_ref().into_c_string());
2047+
let path = if cfg!(windows) {
2048+
// `git_ignore_path_is_ignored` dose not work with windows path separator
2049+
// so we convert \ to /
2050+
try!(::std::ffi::CString::new(path.as_ref().to_string_lossy().replace('\\', "/")))
2051+
} else {
2052+
try!(path.as_ref().into_c_string())
2053+
};
20482054
let mut ignored: c_int = 0;
20492055
unsafe {
20502056
try_call!(raw::git_ignore_path_is_ignored(&mut ignored, self.raw, path));
@@ -2536,8 +2542,15 @@ mod tests {
25362542

25372543
let _ = repo.add_ignore_rule("/foo");
25382544
assert!(repo.is_path_ignored(Path::new("/foo")).unwrap());
2545+
if cfg!(windows){
2546+
assert!(repo.is_path_ignored(Path::new("\\foo\\thing")).unwrap());
2547+
}
2548+
25392549

25402550
let _ = repo.clear_ignore_rules();
25412551
assert!(!repo.is_path_ignored(Path::new("/foo")).unwrap());
2552+
if cfg!(windows){
2553+
assert!(!repo.is_path_ignored(Path::new("\\foo\\thing")).unwrap());
2554+
}
25422555
}
25432556
}

0 commit comments

Comments
 (0)