Skip to content

Commit 30a7076

Browse files
Eh2406alexcrichton
authored andcommitted
work around for windows path separator for status_file (#341)
1 parent abe3eaf commit 30a7076

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/repo.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,13 @@ impl Repository {
804804
/// through looking for the path that you are interested in.
805805
pub fn status_file(&self, path: &Path) -> Result<Status, Error> {
806806
let mut ret = 0 as c_uint;
807-
let path = try!(path.into_c_string());
807+
let path = if cfg!(windows) {
808+
// `git_status_file` dose not work with windows path separator
809+
// so we convert \ to /
810+
try!(::std::ffi::CString::new(path.to_string_lossy().replace('\\', "/")))
811+
} else {
812+
try!(path.into_c_string())
813+
};
808814
unsafe {
809815
try_call!(raw::git_status_file(&mut ret, self.raw,
810816
path));

src/status.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,19 @@ mod tests {
400400
fn status_file() {
401401
let (td, repo) = ::test::repo_init();
402402
assert!(repo.status_file(Path::new("foo")).is_err());
403+
if cfg!(windows) {
404+
assert!(repo.status_file(Path::new("bar\\foo.txt")).is_err());
405+
}
403406
t!(File::create(td.path().join("foo")));
407+
if cfg!(windows) {
408+
t!(::std::fs::create_dir_all(td.path().join("bar")));
409+
t!(File::create(td.path().join("bar").join("foo.txt")));
410+
}
404411
let status = t!(repo.status_file(Path::new("foo")));
405412
assert!(status.contains(::Status::WT_NEW));
413+
if cfg!(windows) {
414+
let status = t!(repo.status_file(Path::new("bar\\foo.txt")));
415+
assert!(status.contains(::Status::WT_NEW));
416+
}
406417
}
407418
}

0 commit comments

Comments
 (0)