// the untracked files are often part of a build and may become relevant
// as part of a future commit.
let index_files = index.iter().map(|entry| {
- use libgit2_sys::GIT_FILEMODE_COMMIT;
- let is_dir = entry.mode == GIT_FILEMODE_COMMIT as u32;
- (join(root, &entry.path), Some(is_dir))
+ use libgit2_sys::{GIT_FILEMODE_COMMIT, GIT_FILEMODE_LINK};
+ // ``is_dir`` is an optimization to avoid calling
+ // ``fs::metadata`` on every file.
+ let is_dir = if entry.mode == GIT_FILEMODE_LINK as u32 {
+ // Let the code below figure out if this symbolic link points
+ // to a directory or not.
+ None
+ } else {
+ Some(entry.mode == GIT_FILEMODE_COMMIT as u32)
+ };
+ (join(root, &entry.path), is_dir)
});
let mut opts = git2::StatusOptions::new();
opts.include_untracked(true);
#[cargo_test]
fn package_symlink_to_submodule() {
+ #[cfg(unix)]
+ use std::os::unix::fs::symlink as symlink;
+ #[cfg(windows)]
+ use std::os::unix::fs::symlink_dir as symlink;
+
let project = git::new("foo", |project| {
project
.file("src/lib.rs", "pub fn foo() {}")
- .symlink("submodule", "submodule-link")
}).unwrap();
let library = git::new("submodule", |library| {
let repository = git2::Repository::open(&project.root()).unwrap();
let url = path2url(library.root()).to_string();
git::add_submodule(&repository, &url, Path::new("submodule"));
+ t!(symlink(&project.root().join("submodule"), &project.root().join("submodule-link")));
+ git::add(&repository);
git::commit(&repository);
let repository = git2::Repository::open(&project.root().join("submodule")).unwrap();