Skip to content
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

Preserve lockfile top comment #6181

Merged
merged 5 commits into from
Oct 18, 2018
Merged
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
10 changes: 10 additions & 0 deletions src/cargo/ops/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ pub fn write_pkg_lockfile(ws: &Workspace, resolve: &Resolve) -> CargoResult<()>

let mut out = String::new();

// Preserve the top comments in the lockfile
// This is in preparation for marking it as generated
// https://github.com/rust-lang/cargo/issues/6180
if let Ok(orig) = &orig {
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
for line in orig.lines().take_while(|line| line.starts_with("#")) {
out.push_str(line);
out.push_str("\n");
}
}

let deps = toml["package"].as_array().unwrap();
for dep in deps.iter() {
let dep = dep.as_table().unwrap();
Expand Down
21 changes: 21 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,24 @@ fn update_precise() {
",
).run();
}

#[test]
fn preserve_top_comment() {
let p = project().file("src/lib.rs", "").build();

p.cargo("update").run();

let mut lockfile = p.read_file("Cargo.lock");
lockfile.insert_str(0, "# @generated\n");
lockfile.insert_str(0, "# some other comment\n");
println!("saving Cargo.lock contents:\n{}", lockfile);

p.change_file("Cargo.lock", &lockfile);

p.cargo("update").run();

let lockfile2 = p.read_file("Cargo.lock");
println!("loaded Cargo.lock contents:\n{}", lockfile2);

assert!(lockfile == lockfile2);
}