Skip to content

Commit dcd0c49

Browse files
committed
Prevent errors if workspace is not in the manifest.
Signed-off-by: David Calavera <[email protected]>
1 parent d5ad2d2 commit dcd0c49

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ fn update_manifest_with_new_member(
10221022
}
10231023
}
10241024
}
1025-
} else {
1025+
} else if workspace_document.contains_key("workspace") {
10261026
let ws = workspace_document["workspace"]
10271027
.as_table_mut()
10281028
.with_context(|| format!("[workspace] is not a table"))?;
@@ -1050,6 +1050,11 @@ fn update_manifest_with_new_member(
10501050
}
10511051

10521052
ws.insert("members", toml_edit::value(array));
1053+
} else {
1054+
let mut array = Array::new();
1055+
array.push(relpath);
1056+
array.decor_mut().set_suffix("\n");
1057+
workspace_document["workspace"]["members"] = toml_edit::value(array);
10531058
}
10541059

10551060
paths::write(&root_manifest_path, workspace_document.to_string())

0 commit comments

Comments
 (0)