From ac97bcf232aa1d1b4cf8ce69ace29a735fda62b2 Mon Sep 17 00:00:00 2001 From: konsti Date: Mon, 16 Feb 2026 17:40:46 +0100 Subject: [PATCH] Don't panic for `uv init / --name foo` (#17983) No test since we don't know where the test runner will have access to `/` or not. I've manually confirmed that `uv init / --name foo` doesn't panic anymore. The error message for it is mediocre but passable (same as e.g. `uv init /usr` on stable, no change just documenting it): ``` error: Failed to initialize Git repository at `/` stdout: stderr: /.git: Permission denied ``` --- crates/uv/src/commands/project/init.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/uv/src/commands/project/init.rs b/crates/uv/src/commands/project/init.rs index ec4795f6d..6c93f2187 100644 --- a/crates/uv/src/commands/project/init.rs +++ b/crates/uv/src/commands/project/init.rs @@ -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}; @@ -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). + 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 {