Skip to content
Merged
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
15 changes: 13 additions & 2 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::str::FromStr;

use anyhow::{Context, Result, anyhow};
use anyhow::{Context, Result, anyhow, bail};
use owo_colors::OwoColorize;
use toml_edit::{InlineTable, Value};
use tracing::{debug, trace, warn};
Expand Down Expand Up @@ -311,7 +311,18 @@ async fn init_project(
// Discover the current workspace, if it exists.
let workspace_cache = WorkspaceCache::default();
let workspace = {
let parent = path.parent().expect("Project path has no parent");
let parent = match path.parent() {
Some(parent) => parent,
None => {
if path.is_dir() {
// Support creating a project in the filesystem root (`/` on Unix).
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less because we encourage it, and more because I expect there some strange environment where a filesystem root is a reasonable directory.

path
} else {
// Not sure how we'd end up here, but we need to handle the case.
bail!("Project directory has no parent directory");
}
}
};
match Workspace::discover(
parent,
&DiscoveryOptions {
Expand Down
Loading