Skip to content
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
1 change: 0 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ jobs:

- name: Test pcb import (E2E)
run: |
pcb new --workspace test-import --repo github.com/test/test-import
find kicad-test-fixtures -name '*.kicad_pro' | while IFS= read -r pro; do
echo "=== Importing $pro ==="
pcb import "$pro" ./test-import
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to Semantic Versioning (https://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- `pcb import` now scaffolds a full workspace (git init, README, .gitignore) when the output directory is new, matching `pcb new --workspace`.

## [0.3.39] - 2026-02-11

### Fixed
Expand Down
33 changes: 8 additions & 25 deletions crates/pcb/src/import/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ fn ensure_workspace_root(path: &Path) -> Result<PathBuf> {
if path.exists() && !path.is_dir() {
anyhow::bail!("Output directory is not a directory: {}", path.display());
}
if !path.exists() {
let created = !path.exists();
if created {
fs::create_dir_all(path)
.with_context(|| format!("Failed to create output directory: {}", path.display()))?;
}
Expand All @@ -49,12 +50,6 @@ fn ensure_workspace_root(path: &Path) -> Result<PathBuf> {
pcb_toml.display()
);
}
if !config.is_v2() {
anyhow::bail!(
"Output directory contains a legacy (V1) workspace pcb.toml; run `pcb migrate`: {}",
pcb_toml.display()
);
}
return Ok(workspace_root);
}

Expand All @@ -74,23 +69,11 @@ fn ensure_workspace_root(path: &Path) -> Result<PathBuf> {
);
}

write_minimal_workspace_pcb_toml(&pcb_toml)?;
if let Err(e) = crate::new::init_workspace(&workspace_root, "") {
if created {
let _ = fs::remove_dir_all(&workspace_root);
}
return Err(e);
}
Ok(workspace_root)
}

fn write_minimal_workspace_pcb_toml(path: &Path) -> Result<()> {
use pcb_zen_core::config::{default_members, PcbToml, WorkspaceConfig};

let config = PcbToml {
workspace: Some(WorkspaceConfig {
pcb_version: Some(crate::migrate::codemods::manifest_v2::pcb_version_from_cargo()),
members: default_members(),
..WorkspaceConfig::default()
}),
..PcbToml::default()
};

let content = toml::to_string_pretty(&config)?;
fs::write(path, content).with_context(|| format!("Failed to write {}", path.display()))?;
Ok(())
}
79 changes: 43 additions & 36 deletions crates/pcb/src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,36 +231,20 @@ fn prompt_new_package() -> Result<()> {
execute_new_package(&path)
}

fn execute_new_workspace(workspace: &str, repo: Option<&str>) -> Result<()> {
if get_workspace().is_some() {
bail!("Cannot create a workspace inside an existing workspace");
}

validate_name(workspace, "Workspace")?;

let repo =
repo.ok_or_else(|| anyhow::anyhow!("--repo is required when creating a workspace"))?;
let repository = clean_repo_url(repo)?;

let workspace_path = Path::new(workspace);

if workspace_path.exists() {
bail!("Directory '{}' already exists", workspace);
}

std::fs::create_dir_all(workspace_path)
.with_context(|| format!("Failed to create directory '{}'", workspace))?;

let status = Command::new("git")
.args(["init", "-b", "main"])
.current_dir(workspace_path)
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.context("Failed to run 'git init'")?;

if !status.success() {
bail!("'git init' failed with exit code: {:?}", status.code());
/// Initialize workspace scaffolding in an existing directory: pcb.toml, README,
/// .gitignore, git init, and skill path. `repository` may be empty.
pub(crate) fn init_workspace(dir: &Path, repository: &str) -> Result<()> {
if !dir.join(".git").exists() {
let status = Command::new("git")
.args(["init", "-b", "main"])
.current_dir(dir)
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.context("Failed to run 'git init'")?;
if !status.success() {
bail!("'git init' failed with exit code: {:?}", status.code());
}
}

let env = create_template_env();
Expand All @@ -274,21 +258,44 @@ fn execute_new_workspace(workspace: &str, repo: Option<&str>) -> Result<()> {
.unwrap()
.render(&ctx)
.context("Failed to render pcb.toml template")?;
std::fs::write(workspace_path.join("pcb.toml"), pcb_toml_content)
.context("Failed to write pcb.toml")?;
std::fs::write(dir.join("pcb.toml"), pcb_toml_content).context("Failed to write pcb.toml")?;

let readme_content = env
.get_template("workspace_readme")
.unwrap()
.render(&ctx)
.context("Failed to render README.md template")?;
std::fs::write(workspace_path.join("README.md"), readme_content)
.context("Failed to write README.md")?;
std::fs::write(dir.join("README.md"), readme_content).context("Failed to write README.md")?;

std::fs::write(workspace_path.join(".gitignore"), GITIGNORE_TEMPLATE)
std::fs::write(dir.join(".gitignore"), GITIGNORE_TEMPLATE)
.context("Failed to write .gitignore")?;

add_skill_to_path(workspace_path)?;
add_skill_to_path(dir)?;

Ok(())
}

fn execute_new_workspace(workspace: &str, repo: Option<&str>) -> Result<()> {
if get_workspace().is_some() {
bail!("Cannot create a workspace inside an existing workspace");
}

validate_name(workspace, "Workspace")?;

let repo =
repo.ok_or_else(|| anyhow::anyhow!("--repo is required when creating a workspace"))?;
let repository = clean_repo_url(repo)?;

let workspace_path = Path::new(workspace);

if workspace_path.exists() {
bail!("Directory '{}' already exists", workspace);
}

std::fs::create_dir_all(workspace_path)
.with_context(|| format!("Failed to create directory '{}'", workspace))?;

init_workspace(workspace_path, &repository)?;

eprintln!(
"{} {} ({})",
Expand Down
4 changes: 2 additions & 2 deletions crates/pcb/src/templates/workspace_pcb_toml.jinja
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
repository = "{{ repository }}"
pcb-version = "{{ pcb_version }}"
{% if repository %}repository = "{{ repository }}"
{% endif %}pcb-version = "{{ pcb_version }}"
members = [
"components/*",
"modules/*",
Expand Down