Skip to content

Fix for #3859 #3868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,6 @@ fn global_config(config: &Config) -> CargoResult<CargoNewConfig> {

/// Recursively list directory contents under `dir`, only visiting files.
///
/// This will also filter out files & files types which we don't want to
/// try generate templates for. Image files, for instance.
///
/// It also filters out certain files & file types, as we don't want t
///
/// We use this instead of std::fs::walk_dir as it is marked as unstable for now
Expand All @@ -663,7 +660,6 @@ fn global_config(config: &Config) -> CargoResult<CargoNewConfig> {
/// http://doc.rust-lang.org/std/fs/fn.read_dir.html
fn walk_template_dir(dir: &Path, cb: &mut FnMut(DirEntry) -> CargoResult<()>) -> CargoResult<()> {
let attr = try!(fs::metadata(&dir));
let ignore_files = vec![".gitignore"];

if !attr.is_dir() {
return Ok(());
Expand All @@ -678,11 +674,6 @@ fn walk_template_dir(dir: &Path, cb: &mut FnMut(DirEntry) -> CargoResult<()>) ->
}
}
} else {
if let Some(file_name) = entry.path().file_name() {
if ignore_files.contains(&file_name.to_str().unwrap()) {
continue
}
}
try!(cb(entry));
}
}
Expand Down
12 changes: 11 additions & 1 deletion tests/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ name = "{{name}}"
version = "0.0.1"
authors = ["{{author}}"]
"#).unwrap();
File::create(&root.join("home/.cargo/templates/testtemplate/LICENSE"))
File::create(&root.join("home/.cargo/templates/testtemplate/LICENSE"))
.unwrap().write_all(br#"
(c) {{year}} {{author}}
"#).unwrap();
File::create(&root.join("home/.cargo/templates/testtemplate/.gitignore"))
.unwrap().write_all(br#"callgrind.out.justfile"#).unwrap();
File::create(&root.join("home/.cargo/templates/testtemplate/src/main.rs"))
.unwrap().write_all(br#"
fn main () {
Expand All @@ -100,14 +102,22 @@ fn main () {
assert_that(&paths::root().join("foo"), existing_dir());
assert_that(&paths::root().join("foo/Cargo.toml"), existing_file());
assert_that(&paths::root().join("foo/LICENSE"), existing_file());
assert_that(&paths::root().join("foo/.gitignore"), existing_file());
assert_that(&paths::root().join("foo/src/main.rs"), existing_file());

// Validate the date templating
let license = paths::root().join("foo/LICENSE");
let mut contents = String::new();
File::open(&license).unwrap().read_to_string(&mut contents).unwrap();
let expected = format!("(c) {} {}", (time::now().tm_year + 1900).to_string(), "foo");
assert!(contents.contains(&expected));

// Validate that we did not blow away .gitignore
let gitignore = paths::root().join("foo/.gitignore");
let mut contents = String::new();
File::open(&gitignore).unwrap().read_to_string(&mut contents).unwrap();
assert!(contents.contains(&"callgrind.out.justfile"));

assert_that(cargo_process("build").cwd(&paths::root().join("foo")),
execs().with_status(0));
assert_that(&paths::root().join(&format!("foo/target/debug/foo{}",
Expand Down