Skip to content

Commit

Permalink
Prevent errors if workspace is not in the manifest.
Browse files Browse the repository at this point in the history
Signed-off-by: David Calavera <[email protected]>
  • Loading branch information
calavera committed Oct 9, 2023
1 parent d5ad2d2 commit dcd0c49
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ fn update_manifest_with_new_member(
}
}
}
} else {
} else if workspace_document.contains_key("workspace") {
let ws = workspace_document["workspace"]
.as_table_mut()
.with_context(|| format!("[workspace] is not a table"))?;
Expand Down Expand Up @@ -1050,6 +1050,11 @@ fn update_manifest_with_new_member(
}

ws.insert("members", toml_edit::value(array));
} else {
let mut array = Array::new();
array.push(relpath);
array.decor_mut().set_suffix("\n");
workspace_document["workspace"]["members"] = toml_edit::value(array);
}

paths::write(&root_manifest_path, workspace_document.to_string())
Expand Down

0 comments on commit dcd0c49

Please sign in to comment.