From 7350cec5da7d39e0b896288a60c8ea191fa133ed Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 4 Aug 2014 07:45:25 -0700 Subject: [PATCH] Ignore Cargo.lock for libs in `cargo-new` The lockfile should only be checked in for bins, not libs. Closes #304 --- src/cargo/ops/cargo_new.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 51e8255d44b..c9f1ccdf007 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -32,7 +32,11 @@ fn mk(path: &Path, name: &str, opts: &NewOptions) -> CargoResult<()> { if opts.git { try!(git!("init", path)); - try!(File::create(&path.join(".gitignore")).write(b"/target\n")); + let mut gitignore = "/target\n".to_string(); + if !opts.bin { + gitignore.push_str("/Cargo.lock\n"); + } + try!(File::create(&path.join(".gitignore")).write(gitignore.as_bytes())); } else { try!(fs::mkdir(path, io::UserRWX)); }