Preserve multiline top comments

This commit is contained in:
Dale Wijnand 2018-10-18 06:44:12 +01:00
parent 0cdb780345
commit ce40ab87c8
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
2 changed files with 5 additions and 6 deletions

View File

@ -43,12 +43,10 @@ pub fn write_pkg_lockfile(ws: &Workspace, resolve: &Resolve) -> CargoResult<()>
let mut out = String::new();
if let Ok(ref orig) = orig {
if let Some(first_line) = orig.lines().into_iter().next() {
if first_line.starts_with("#") {
out.push_str(first_line);
out.push_str("\n");
}
if let Ok(orig) = &orig {
for line in orig.lines().take_while(|line| line.starts_with("#")) {
out.push_str(line);
out.push_str("\n");
}
}

View File

@ -383,6 +383,7 @@ fn preserve_top_comment() {
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);