mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
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.
This commit is contained in:
parent
57aa352da7
commit
54ad4a01df
@ -93,7 +93,6 @@ struct MkOptions<'a> {
|
||||
path: &'a Path,
|
||||
name: &'a str,
|
||||
source_files: Vec<SourceFileInformation>,
|
||||
bin: bool,
|
||||
edition: Option<&'a str>,
|
||||
registry: Option<&'a str>,
|
||||
}
|
||||
@ -448,7 +447,6 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
|
||||
path,
|
||||
name,
|
||||
source_files: vec![plan_new_source_file(opts.kind.is_bin(), name.to_string())],
|
||||
bin: is_bin,
|
||||
edition: opts.edition.as_deref(),
|
||||
registry: opts.registry.as_deref(),
|
||||
};
|
||||
@ -553,7 +551,6 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
|
||||
version_control,
|
||||
path,
|
||||
name,
|
||||
bin: has_bin,
|
||||
source_files: src_paths_types,
|
||||
edition: opts.edition.as_deref(),
|
||||
registry: opts.registry.as_deref(),
|
||||
@ -745,9 +742,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
|
||||
// for all mutually-incompatible VCS in terms of syntax are in sync.
|
||||
let mut ignore = IgnoreList::new();
|
||||
ignore.push("/target", "^target$", "target");
|
||||
if !opts.bin {
|
||||
ignore.push("/Cargo.lock", "^Cargo.lock$", "Cargo.lock");
|
||||
}
|
||||
|
||||
let vcs = opts.version_control.unwrap_or_else(|| {
|
||||
let in_existing_vcs = existing_vcs_repo(path.parent().unwrap_or(path), config.cwd());
|
||||
|
@ -104,7 +104,8 @@ issue][cargo-issues].
|
||||
|
||||
### Why have `Cargo.lock` in version control?
|
||||
|
||||
Whether you do is dependent on the needs of your package.
|
||||
While [`cargo new`] defaults to tracking `Cargo.lock` in version control,
|
||||
whether you do is dependent on the needs of your package.
|
||||
|
||||
The purpose of a `Cargo.lock` lockfile is to describe the state of the world at
|
||||
the time of a successful build.
|
||||
@ -139,6 +140,7 @@ The lockfile can also be a source of merge conflicts.
|
||||
For strategies to verify newer versions of dependencies via CI,
|
||||
see [Verifying Latest Dependencies](guide/continuous-integration.md#verifying-latest-dependencies).
|
||||
|
||||
[`cargo new`]: commands/cargo-new.md
|
||||
[`cargo add`]: commands/cargo-add.md
|
||||
[`cargo install`]: commands/cargo-install.md
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
/target
|
||||
/Cargo.lock
|
||||
|
@ -1,2 +1 @@
|
||||
target
|
||||
Cargo.lock
|
||||
|
@ -1,2 +1 @@
|
||||
target
|
||||
Cargo.lock
|
||||
|
@ -1,2 +1 @@
|
||||
/target
|
||||
/Cargo.lock
|
||||
|
@ -3,4 +3,3 @@
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
/Cargo.lock
|
||||
|
@ -1,2 +1 @@
|
||||
/target
|
||||
/Cargo.lock
|
||||
|
@ -1,2 +1 @@
|
||||
^target$
|
||||
^Cargo.lock$
|
||||
|
@ -1,2 +1 @@
|
||||
/target
|
||||
/Cargo.lock
|
||||
|
@ -1,2 +1 @@
|
||||
/target
|
||||
/Cargo.lock
|
||||
|
@ -6,4 +6,3 @@
|
||||
# already existing elements were commented out
|
||||
|
||||
#/target
|
||||
/Cargo.lock
|
||||
|
@ -1,2 +1 @@
|
||||
^target$
|
||||
^Cargo.lock$
|
||||
|
@ -3,4 +3,3 @@
|
||||
# Added by cargo
|
||||
|
||||
^target$
|
||||
^Cargo.lock$
|
||||
|
@ -95,7 +95,7 @@ fn simple_git() {
|
||||
|
||||
let fp = paths::root().join("foo/.gitignore");
|
||||
let contents = fs::read_to_string(&fp).unwrap();
|
||||
assert_eq!(contents, "/target\n/Cargo.lock\n",);
|
||||
assert_eq!(contents, "/target\n",);
|
||||
|
||||
cargo_process("build").cwd(&paths::root().join("foo")).run();
|
||||
}
|
||||
@ -112,7 +112,7 @@ fn simple_hg() {
|
||||
|
||||
let fp = paths::root().join("foo/.hgignore");
|
||||
let contents = fs::read_to_string(&fp).unwrap();
|
||||
assert_eq!(contents, "^target$\n^Cargo.lock$\n",);
|
||||
assert_eq!(contents, "^target$\n",);
|
||||
|
||||
cargo_process("build").cwd(&paths::root().join("foo")).run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user