Skip to content

Commit

Permalink
Auto merge of #6181 - dwijnand:preserve-lockfile-top-comment, r=alexc…
Browse files Browse the repository at this point in the history
…richton

Preserve lockfile top comment

Refs #6180
  • Loading branch information
bors committed Oct 18, 2018
2 parents cbde1c6 + 32fbfe3 commit 8522a88
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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 {
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);
}

0 comments on commit 8522a88

Please sign in to comment.