Skip to content

Commit c3986f3

Browse files
demurgosepage
authored andcommitted
fix(new): Don't ignore Cargo.lock for all package types
Following the default guidance to commit a lockfile, this updates `cargo new` to do it by default.
1 parent f627c6c commit c3986f3

File tree

15 files changed

+5
-21
lines changed

15 files changed

+5
-21
lines changed

src/cargo/ops/cargo_new.rs

-6
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ struct MkOptions<'a> {
9393
path: &'a Path,
9494
name: &'a str,
9595
source_files: Vec<SourceFileInformation>,
96-
bin: bool,
9796
edition: Option<&'a str>,
9897
registry: Option<&'a str>,
9998
}
@@ -448,7 +447,6 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
448447
path,
449448
name,
450449
source_files: vec![plan_new_source_file(opts.kind.is_bin(), name.to_string())],
451-
bin: is_bin,
452450
edition: opts.edition.as_deref(),
453451
registry: opts.registry.as_deref(),
454452
};
@@ -553,7 +551,6 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
553551
version_control,
554552
path,
555553
name,
556-
bin: has_bin,
557554
source_files: src_paths_types,
558555
edition: opts.edition.as_deref(),
559556
registry: opts.registry.as_deref(),
@@ -745,9 +742,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
745742
// for all mutually-incompatible VCS in terms of syntax are in sync.
746743
let mut ignore = IgnoreList::new();
747744
ignore.push("/target", "^target$", "target");
748-
if !opts.bin {
749-
ignore.push("/Cargo.lock", "^Cargo.lock$", "Cargo.lock");
750-
}
751745

752746
let vcs = opts.version_control.unwrap_or_else(|| {
753747
let in_existing_vcs = existing_vcs_repo(path.parent().unwrap_or(path), config.cwd());

src/doc/src/faq.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ issue][cargo-issues].
104104

105105
### Why have `Cargo.lock` in version control?
106106

107-
Whether you do is dependent on the needs of your package.
107+
While [`cargo new`] defaults to tracking `Cargo.lock` in version control,
108+
whether you do is dependent on the needs of your package.
108109

109110
The purpose of a `Cargo.lock` lockfile is to describe the state of the world at
110111
the time of a successful build.
@@ -139,6 +140,7 @@ The lockfile can also be a source of merge conflicts.
139140
For strategies to verify newer versions of dependencies via CI,
140141
see [Verifying Latest Dependencies](guide/continuous-integration.md#verifying-latest-dependencies).
141142

143+
[`cargo new`]: commands/cargo-new.md
142144
[`cargo add`]: commands/cargo-add.md
143145
[`cargo install`]: commands/cargo-install.md
144146

Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/target
2-
/Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
target
2-
Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
target
2-
Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/target
2-
/Cargo.lock

tests/testsuite/init/git_ignore_exists_no_conflicting_entries/out/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
# Added by cargo
44

55
/target
6-
/Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/target
2-
/Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
^target$
2-
^Cargo.lock$
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/target
2-
/Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/target
2-
/Cargo.lock

tests/testsuite/init/simple_git_ignore_exists/out/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
# already existing elements were commented out
77

88
#/target
9-
/Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
^target$
2-
^Cargo.lock$

tests/testsuite/init/simple_hg_ignore_exists/out/.hgignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
# Added by cargo
44

55
^target$
6-
^Cargo.lock$

tests/testsuite/new.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn simple_git() {
9595

9696
let fp = paths::root().join("foo/.gitignore");
9797
let contents = fs::read_to_string(&fp).unwrap();
98-
assert_eq!(contents, "/target\n/Cargo.lock\n",);
98+
assert_eq!(contents, "/target\n",);
9999

100100
cargo_process("build").cwd(&paths::root().join("foo")).run();
101101
}
@@ -112,7 +112,7 @@ fn simple_hg() {
112112

113113
let fp = paths::root().join("foo/.hgignore");
114114
let contents = fs::read_to_string(&fp).unwrap();
115-
assert_eq!(contents, "^target$\n^Cargo.lock$\n",);
115+
assert_eq!(contents, "^target$\n",);
116116

117117
cargo_process("build").cwd(&paths::root().join("foo")).run();
118118
}

0 commit comments

Comments
 (0)