Skip to content
This repository was archived by the owner on Nov 3, 2026. It is now read-only.
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
42 changes: 21 additions & 21 deletions src/clone_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl CloneQueue {
true
}

/// Add multiple tasks from a .meta file
/// Add multiple tasks from a .meta.yaml file
pub fn push_from_meta(&self, base_dir: &Path, depth_level: usize) -> anyhow::Result<usize> {
// Check meta depth limit
if let Some(max_depth) = self.meta_depth {
Expand All @@ -95,8 +95,8 @@ impl CloneQueue {
}
}

let Some((meta_path, _format)) = config::find_meta_config_in(base_dir)? else {
debug!("No .meta config found in {}", escape_path(base_dir));
let Some(meta_path) = config::find_meta_config_in(base_dir)? else {
debug!("No .meta.yaml found in {}", escape_path(base_dir));
return Ok(0);
};

Expand Down Expand Up @@ -178,7 +178,7 @@ impl CloneQueue {
self.git_depth.as_deref()
}

/// Mark a task as completed and check for nested .meta files
/// Mark a task as completed and check for nested .meta.yaml files
pub fn mark_completed(&self, task: &CloneTask) -> anyhow::Result<usize> {
self.total_completed.fetch_add(1, Ordering::SeqCst);

Expand All @@ -187,17 +187,17 @@ impl CloneQueue {
completed.insert(task.target_path.clone());
}

// Check for nested .meta file and add children to queue
// Check for nested .meta.yaml file and add children to queue
let added = self.push_from_meta(&task.target_path, task.depth_level + 1)?;
debug!(
"mark_completed: {} -> {} nested tasks discovered",
task.name, added
);

// Warn if the config declared meta: true but no nested .meta was found
// Warn if the config declared meta: true but no nested .meta.yaml was found
if task.is_meta && added == 0 {
warn!(
"'{}' is declared with `meta: true` but no .meta config was found inside it",
"'{}' is declared with `meta: true` but no .meta.yaml was found inside it",
task.name
);
}
Expand Down Expand Up @@ -263,33 +263,33 @@ mod tests {
#[cfg(unix)]
#[test]
fn push_from_meta_does_not_look_past_the_depth_limit() {
// child exists with a dangling .meta; at depth limit 0 it is never
// child exists with a dangling .meta.yaml; at depth limit 0 it is never
// read, so seeding still queues the missing sibling
let dir = tempfile::tempdir().unwrap();
std::fs::create_dir(dir.path().join("child")).unwrap();
std::fs::write(
dir.path().join(".meta"),
dir.path().join(".meta.yaml"),
r#"{"projects": {"child": {"repo": "u", "meta": true}, "sib": "u2"}}"#,
)
.unwrap();
std::os::unix::fs::symlink("missing.json", dir.path().join("child/.meta")).unwrap();
std::os::unix::fs::symlink("missing.yaml", dir.path().join("child/.meta.yaml")).unwrap();
let queue = CloneQueue::new(None, Some(0));
assert_eq!(queue.push_from_meta(dir.path(), 0).unwrap(), 1);
}

#[cfg(unix)]
#[test]
fn push_from_meta_fails_on_a_nested_config_it_cannot_read() {
// child/.meta is a link to nowhere: its repos are unknown, which is
// child/.meta.yaml is a link to nowhere: its repos are unknown, which is
// an error, not "no nested repos"
let dir = tempfile::tempdir().unwrap();
std::fs::create_dir(dir.path().join("child")).unwrap();
std::fs::write(
dir.path().join(".meta"),
dir.path().join(".meta.yaml"),
r#"{"projects": {"child": {"repo": "u", "meta": true}}}"#,
)
.unwrap();
std::os::unix::fs::symlink("missing.json", dir.path().join("child/.meta")).unwrap();
std::os::unix::fs::symlink("missing.yaml", dir.path().join("child/.meta.yaml")).unwrap();
let queue = CloneQueue::new(None, None);
let err = queue.push_from_meta(dir.path(), 0).unwrap_err();
assert!(format!("{err:#}").contains("Cannot read"), "{err:#}");
Expand Down Expand Up @@ -388,7 +388,7 @@ mod tests {
fn push_from_meta_discovers_projects() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(
dir.path().join(".meta"),
dir.path().join(".meta.yaml"),
r#"{"projects": {
"alpha": "git@github.com:org/alpha.git",
"beta": "git@github.com:org/beta.git"
Expand All @@ -414,7 +414,7 @@ mod tests {
fn push_from_meta_respects_depth_limit() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(
dir.path().join(".meta"),
dir.path().join(".meta.yaml"),
r#"{"projects": {"repo": "git@github.com:org/repo.git"}}"#,
)
.unwrap();
Expand All @@ -435,7 +435,7 @@ mod tests {
// Create the project directory so it appears "already cloned"
std::fs::create_dir(dir.path().join("existing")).unwrap();
std::fs::write(
dir.path().join(".meta"),
dir.path().join(".meta.yaml"),
r#"{"projects": {"existing": "git@github.com:org/existing.git"}}"#,
)
.unwrap();
Expand All @@ -449,7 +449,7 @@ mod tests {
fn push_from_meta_skips_projects_without_repo() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(
dir.path().join(".meta"),
dir.path().join(".meta.yaml"),
r#"{"projects": {"no-repo": {"path": "no-repo"}}}"#,
)
.unwrap();
Expand All @@ -463,7 +463,7 @@ mod tests {
fn push_from_meta_preserves_is_meta_flag() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(
dir.path().join(".meta"),
dir.path().join(".meta.yaml"),
r#"{"projects": {
"nested": {"repo": "git@github.com:org/nested.git", "meta": true},
"plain": "git@github.com:org/plain.git"
Expand All @@ -490,9 +490,9 @@ mod tests {
let child_dir = dir.path().join("child");
std::fs::create_dir(&child_dir).unwrap();

// Child has its own .meta with a grandchild
// Child has its own .meta.yaml with a grandchild
std::fs::write(
child_dir.join(".meta"),
child_dir.join(".meta.yaml"),
r#"{"projects": {"grandchild": "git@github.com:org/grandchild.git"}}"#,
)
.unwrap();
Expand All @@ -516,7 +516,7 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
let child_dir = dir.path().join("child");
std::fs::create_dir(&child_dir).unwrap();
// No .meta inside child
// No .meta.yaml inside child

let queue = CloneQueue::new(None, None);
let task = CloneTask {
Expand Down
63 changes: 29 additions & 34 deletions src/worktree/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Utility functions for worktree management.

use anyhow::{Context, Result};
use meta_core::config::ConfigFormat;
use meta_core::display::{escape, escape_path};
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -32,22 +31,22 @@ pub fn resolve_worktree_root(meta_dir: Option<&Path>) -> Result<PathBuf> {
if let Ok(env_path) = std::env::var("META_WORKTREES") {
return Ok(PathBuf::from(env_path));
}
// 2. Check worktrees_dir in .meta config. In a worktree set, of the
// 2. Check worktrees_dir in .meta.yaml. In a worktree set, of the
// checkout it stands for: its sets live where that one's do
if let Some(dir) = meta_dir.map(owner_dir) {
let dir = dir.as_path();
// The config's rules for the worktree directory (inside the
// workspace, not inside a project, not into .git) hold here too,
// whoever ran this plugin
if let Some((config, _)) = meta_core::config::find_meta_config_in(dir)? {
if let Some(config) = meta_core::config::find_meta_config_in(dir)? {
meta_core::config::parse_meta_config(&config)?;
}
if let Some(configured) = read_worktrees_dir_from_config(dir)? {
// Worktrees are created and removed there, so a committed config
// may not point it outside the workspace
let relative = meta_core::config::relative_dir(dir, &configured).map_err(|why| {
anyhow::anyhow!(
"Invalid worktrees_dir in the .meta of {}: {why} (use META_WORKTREES \
"Invalid worktrees_dir in the .meta.yaml of {}: {why} (use META_WORKTREES \
for a directory elsewhere)",
escape_path(dir)
)
Expand Down Expand Up @@ -75,18 +74,14 @@ pub fn resolve_worktree_root(meta_dir: Option<&Path>) -> Result<PathBuf> {
/// [`meta_core::config::find_meta_config_in`]) as a JSON value, if there is
/// one. One that can't be read or parsed is an error.
pub fn read_meta_config_value(meta_dir: &Path) -> Result<Option<serde_json::Value>> {
let Some((path, format)) = meta_core::config::find_meta_config_in(meta_dir)? else {
let Some(path) = meta_core::config::find_meta_config_in(meta_dir)? else {
return Ok(None);
};
let content = std::fs::read_to_string(&path)
.with_context(|| format!("Cannot read {}", escape_path(&path)))?;
let value = match format {
ConfigFormat::Json => serde_json::from_str(&content).map_err(anyhow::Error::from),
ConfigFormat::Yaml => serde_yaml_ng::from_str::<serde_yaml_ng::Value>(&content)
.map_err(anyhow::Error::from)
.and_then(|v| serde_json::to_value(v).map_err(anyhow::Error::from)),
};
value
serde_yaml_ng::from_str::<serde_yaml_ng::Value>(&content)
.map_err(anyhow::Error::from)
.and_then(|v| serde_json::to_value(v).map_err(anyhow::Error::from))
.map(Some)
.with_context(|| format!("Cannot parse {}", escape_path(&path)))
}
Expand All @@ -105,7 +100,7 @@ pub fn find_meta_dir() -> Option<PathBuf> {
pub fn require_meta_dir() -> Result<PathBuf> {
let cwd = std::env::current_dir()?;
meta_core::config::nearest_meta_dir(&cwd)?
.ok_or_else(|| anyhow::anyhow!("Not inside a meta project (no .meta found)"))
.ok_or_else(|| anyhow::anyhow!("Not inside a meta project (no .meta.yaml found)"))
}

/// The directory of the worktree set `name` under `worktree_root`. A symlink
Expand Down Expand Up @@ -177,10 +172,10 @@ pub fn discover_and_validate_worktree(
Ok(repos)
}

/// Load and parse the .meta config, returning the project list.
/// Load and parse the .meta.yaml, returning the project list.
pub fn load_projects(meta_dir: &Path) -> Result<Vec<meta_core::config::ProjectInfo>> {
let (config_path, _) = meta_core::config::find_meta_config(meta_dir, None)?
.ok_or_else(|| anyhow::anyhow!("No .meta config found in {}", escape_path(meta_dir)))?;
let config_path = meta_core::config::find_meta_config(meta_dir, None)?
.ok_or_else(|| anyhow::anyhow!("No .meta.yaml found in {}", escape_path(meta_dir)))?;
let (projects, _) = meta_core::config::parse_meta_config(&config_path)?;
Ok(projects)
}
Expand Down Expand Up @@ -287,7 +282,7 @@ pub fn dest_in_set(wt_dir: &Path, place: &str) -> Result<PathBuf, String> {

/// Look up a project by alias, supporting nested paths like "vendor/tree-sitter-markdown".
///
/// For simple aliases (no `/`), uses flat lookup from the current .meta.
/// For simple aliases (no `/`), uses flat lookup from the current .meta.yaml.
/// For nested paths, walks the meta tree recursively to find the project.
///
/// Returns the resolved path and project info.
Expand Down Expand Up @@ -617,7 +612,7 @@ mod tests {

let tmp = tempfile::tempdir().unwrap();
std::fs::write(
tmp.path().join(".meta"),
tmp.path().join(".meta.yaml"),
r#"{"projects": {"vendor": {"repo": "git@github.com:org/vendor.git", "meta": true}}}"#,
)
.unwrap();
Expand Down Expand Up @@ -857,7 +852,7 @@ mod tests {
fn lookup_nested_simple_alias_works() {
let tmp = tempfile::tempdir().unwrap();
std::fs::write(
tmp.path().join(".meta"),
tmp.path().join(".meta.yaml"),
r#"{"projects": {"backend": "git@github.com:org/backend.git"}}"#,
)
.unwrap();
Expand All @@ -875,16 +870,16 @@ mod tests {
let nested = vendor.join("nested-lib");
std::fs::create_dir_all(&nested).unwrap();

// Root .meta - vendor is a nested meta repo (has repo URL + meta: true)
// Root .meta.yaml - vendor is a nested meta repo (has repo URL + meta: true)
std::fs::write(
tmp.path().join(".meta"),
tmp.path().join(".meta.yaml"),
r#"{"projects": {"vendor": {"repo": "git@github.com:org/vendor.git", "meta": true}}}"#,
)
.unwrap();

// Nested .meta inside vendor (simulates what exists after cloning vendor)
// Nested .meta.yaml inside vendor (simulates what exists after cloning vendor)
std::fs::write(
vendor.join(".meta"),
vendor.join(".meta.yaml"),
r#"{"projects": {"nested-lib": "git@github.com:org/nested-lib.git"}}"#,
)
.unwrap();
Expand All @@ -900,7 +895,7 @@ mod tests {
std::fs::create_dir(tmp.path().join("vendor")).unwrap();

std::fs::write(
tmp.path().join(".meta"),
tmp.path().join(".meta.yaml"),
r#"{"projects": {"vendor": {"repo": "git@github.com:org/vendor.git", "meta": true}}}"#,
)
.unwrap();
Expand All @@ -916,7 +911,7 @@ mod tests {
fn lookup_nested_unknown_simple_alias_fails() {
let tmp = tempfile::tempdir().unwrap();
std::fs::write(
tmp.path().join(".meta"),
tmp.path().join(".meta.yaml"),
r#"{"projects": {"backend": "git@github.com:org/backend.git"}}"#,
)
.unwrap();
Expand All @@ -937,12 +932,12 @@ mod tests {
std::fs::create_dir_all(&nested).unwrap();

std::fs::write(
tmp.path().join(".meta"),
tmp.path().join(".meta.yaml"),
r#"{"projects": {"vendor": {"repo": "git@github.com:org/vendor.git", "meta": true}}}"#,
)
.unwrap();
std::fs::write(
vendor.join(".meta"),
vendor.join(".meta.yaml"),
r#"{"projects": {"lib": "git@github.com:org/lib.git"}}"#,
)
.unwrap();
Expand Down Expand Up @@ -970,16 +965,16 @@ mod tests {
let custom_path = vendor.join("packages/mylib");
std::fs::create_dir_all(&custom_path).unwrap();

// Root .meta - vendor is a nested meta repo
// Root .meta.yaml - vendor is a nested meta repo
std::fs::write(
tmp.path().join(".meta"),
tmp.path().join(".meta.yaml"),
r#"{"projects": {"vendor": {"repo": "git@github.com:org/vendor.git", "meta": true}}}"#,
)
.unwrap();

// Nested .meta with custom path
// Nested .meta.yaml with custom path
std::fs::write(
vendor.join(".meta"),
vendor.join(".meta.yaml"),
r#"{"projects": {"mylib": {"repo": "git@github.com:org/mylib.git", "path": "packages/mylib"}}}"#,
)
.unwrap();
Expand All @@ -1001,21 +996,21 @@ mod tests {

// Root tracks vendor
std::fs::write(
tmp.path().join(".meta"),
tmp.path().join(".meta.yaml"),
r#"{"projects": {"vendor": {"repo": "git@github.com:org/vendor.git", "meta": true}}}"#,
)
.unwrap();

// Vendor tracks sub-vendor
std::fs::write(
vendor.join(".meta"),
vendor.join(".meta.yaml"),
r#"{"projects": {"sub-vendor": {"repo": "git@github.com:org/sub-vendor.git", "meta": true}}}"#,
)
.unwrap();

// Sub-vendor tracks deep-lib
std::fs::write(
sub_vendor.join(".meta"),
sub_vendor.join(".meta.yaml"),
r#"{"projects": {"deep-lib": "git@github.com:org/deep-lib.git"}}"#,
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/worktree/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::process::{Command, Stdio};
use super::helpers::read_meta_config_value;
use super::types::{CreateRepoEntry, PruneEntry};

/// Fire a worktree lifecycle hook if configured in `.meta`.
/// Fire a worktree lifecycle hook if configured in `.meta.yaml`.
///
/// Reads the `.meta` config for `worktree.hooks.<hook_name>`.
/// Reads the `.meta.yaml` config for `worktree.hooks.<hook_name>`.
/// If configured, spawns the command and pipes `payload` JSON to stdin.
/// The hook's stderr goes to meta's stderr, as git does for its hooks; a
/// pipe that nobody reads would block a verbose hook forever.
Expand Down
2 changes: 1 addition & 1 deletion src/worktree/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::safety::{relative_label, RemovalCheck};
pub struct Workspace {
pub root: PathBuf,
/// The git directory of each repository (the root's own, then every one
/// in its `.meta` tree, nested ones included): where the records of the
/// in its `.meta.yaml` tree, nested ones included): where the records of the
/// worktrees made from it are.
pub repos: Vec<PathBuf>,
/// What couldn't be read (the project tree, a repository), with why:
Expand Down
Loading