From 5cca98bed5e6c93e77b3c160e76e8d6885151c2e Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:27:52 -0700 Subject: [PATCH 1/9] fix: escape untrusted values in project list The project tree, root remote URL and dependents list are printed through meta_core::display::escape. CI clones sibling repos from the same branch when it exists. Implements [[tasks/harmony-2749]] --- .github/workflows/ci.yml | 2 ++ src/lib.rs | 46 +++++++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef9028e..b2788c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,6 +78,7 @@ jobs: path: meta_project_cli - name: Clone dependencies + shell: bash env: BRANCH: ${{ github.head_ref || github.ref_name }} run: | @@ -130,6 +131,7 @@ jobs: path: meta_project_cli - name: Clone dependencies + shell: bash env: BRANCH: ${{ github.head_ref || github.ref_name }} run: | diff --git a/src/lib.rs b/src/lib.rs index 0e08a25..0d112e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,10 @@ //! Provides project management commands for meta repositories. use meta_cli::config::{self, MetaTreeNode, ProjectInfo}; +use meta_cli::display::escape; use meta_cli::worktree; use serde::Serialize; +use std::borrow::Cow; use std::collections::{HashMap, HashSet}; use std::path::Path; use std::process::Command; @@ -443,8 +445,9 @@ fn get_git_remote_url(dir: &Path) -> Option { } /// A project's remote URL as shown in `meta project list`. -fn remote_label(repo: Option<&str>) -> &str { - repo.filter(|r| !r.is_empty()).unwrap_or("no remote") +fn remote_label(repo: Option<&str>) -> Cow<'_, str> { + repo.filter(|r| !r.is_empty()) + .map_or(Cow::Borrowed("no remote"), escape) } /// Format a project tree with box-drawing characters: each project's name, its @@ -461,20 +464,21 @@ fn format_project_tree(nodes: &[ProjectTreeNode], output: &mut String, prefix: & let tags_str = if node.tags.is_empty() { String::new() } else { - format!(" [{}]", node.tags.join(", ")) + let tags: Vec<_> = node.tags.iter().map(|t| escape(t)).collect(); + format!(" [{}]", tags.join(", ")) }; let path_str = if node.path == node.name { String::new() } else { - format!(" \u{2192} {}", node.path) + format!(" \u{2192} {}", escape(&node.path)) }; output.push_str(&format!( "{}{}{}{} ({}){}\n", prefix, connector, - node.name, + escape(&node.name), path_str, remote_label(node.repo.as_deref()), tags_str @@ -565,7 +569,10 @@ fn handle_project_dependents( }; let Some(dependents) = find_dependents(&project_name, &all_projects) else { - return CommandResult::Error(format!("Unknown project or alias: {project_name}")); + return CommandResult::Error(format!( + "Unknown project or alias: {}", + escape(&project_name) + )); }; if options.json_output { @@ -576,9 +583,13 @@ fn handle_project_dependents( CommandResult::Message(json) } else { if dependents.is_empty() { - CommandResult::Message(format!("No projects depend on '{project_name}'.")) + CommandResult::Message(format!( + "No projects depend on '{}'.", + escape(&project_name) + )) } else { - CommandResult::Message(dependents.join("\n")) + let names: Vec<_> = dependents.iter().map(|d| escape(d)).collect(); + CommandResult::Message(names.join("\n")) } } } @@ -958,6 +969,25 @@ mod tests { ); } + #[test] + fn test_format_project_tree_escapes_control_characters() { + let nodes = vec![ProjectTreeNode { + name: "x\u{1b}]0;PWNED\u{7}".to_string(), + path: "t\u{1b}[1A".to_string(), + repo: Some("u\u{9b}2J".to_string()), + tags: vec!["n\nfake".to_string()], + is_meta: false, + projects: vec![], + }]; + + let mut output = String::new(); + format_project_tree(&nodes, &mut output, ""); + assert_eq!( + output, + "\u{2514}\u{2500}\u{2500} x\\u{1b}]0;PWNED\\u{7} \u{2192} t\\u{1b}[1A (u\\u{9b}2J) [n\\nfake]\n" + ); + } + #[test] fn test_format_project_tree_without_remote() { let nodes = vec![ProjectTreeNode { From ac9dc1da9dbb4cbad43a899ffec9c4dd9d6e49f4 Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:27:52 -0700 Subject: [PATCH 2/9] fix: escape plugin errors Errors are escaped where they leave the plugin. Implements [[tasks/harmony-2749]] --- src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.rs b/src/main.rs index 8c8a76e..9af4035 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ //! meta-project subprocess plugin use indexmap::IndexMap; +use meta_cli::display::escape_lines; use meta_plugin_protocol::{ run_plugin, CommandResult, PluginDefinition, PluginHelp, PluginInfo, PluginRequest, }; @@ -49,7 +50,16 @@ fn main() { }); } +/// Errors carry paths and names from git and the filesystem, so they are +/// escaped before they reach the terminal. fn execute(request: PluginRequest) -> CommandResult { + match execute_request(request) { + CommandResult::Error(e) => CommandResult::Error(escape_lines(&e).into_owned()), + other => other, + } +} + +fn execute_request(request: PluginRequest) -> CommandResult { let cwd = if request.cwd.is_empty() { match std::env::current_dir() { Ok(d) => d, From ee7b077da72f1b54d986ce793349c7d852e6be0c Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:27:52 -0700 Subject: [PATCH 3/9] ci: fall back to main only when the branch does not exist Implements [[tasks/harmony-2749]] --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2788c7..cddf7a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,12 +31,17 @@ jobs: BRANCH: ${{ github.head_ref || github.ref_name }} run: | for repo in meta_plugin_protocol meta_cli meta_core meta_git_lib loop_lib; do - if git clone --depth 1 -b "$BRANCH" "https://github.com/gitkb/${repo}.git" 2>/dev/null; then - echo "Cloned ${repo}@${BRANCH}" - elif git clone --depth 1 "https://github.com/gitkb/${repo}.git"; then - echo "Branch ${BRANCH} not found for ${repo}; falling back to default branch" + url="https://github.com/gitkb/${repo}.git" + # Exit code 2 means the branch does not exist; anything else is an error + status=0 + git ls-remote --exit-code --heads "$url" "$BRANCH" > /dev/null || status=$? + if [ "$status" -eq 0 ]; then + git clone --depth 1 -b "$BRANCH" "$url" + elif [ "$status" -eq 2 ]; then + echo "Branch ${BRANCH} not found for ${repo}; using the default branch" + git clone --depth 1 "$url" else - echo "::error::Failed to clone ${repo}" + echo "::error::Failed to look up ${repo}" exit 1 fi done @@ -83,12 +88,17 @@ jobs: BRANCH: ${{ github.head_ref || github.ref_name }} run: | for repo in meta_plugin_protocol meta_cli meta_core meta_git_lib loop_lib; do - if git clone --depth 1 -b "$BRANCH" "https://github.com/gitkb/${repo}.git" 2>/dev/null; then - echo "Cloned ${repo}@${BRANCH}" - elif git clone --depth 1 "https://github.com/gitkb/${repo}.git"; then - echo "Branch ${BRANCH} not found for ${repo}; falling back to default branch" + url="https://github.com/gitkb/${repo}.git" + # Exit code 2 means the branch does not exist; anything else is an error + status=0 + git ls-remote --exit-code --heads "$url" "$BRANCH" > /dev/null || status=$? + if [ "$status" -eq 0 ]; then + git clone --depth 1 -b "$BRANCH" "$url" + elif [ "$status" -eq 2 ]; then + echo "Branch ${BRANCH} not found for ${repo}; using the default branch" + git clone --depth 1 "$url" else - echo "::error::Failed to clone ${repo}" + echo "::error::Failed to look up ${repo}" exit 1 fi done @@ -136,12 +146,17 @@ jobs: BRANCH: ${{ github.head_ref || github.ref_name }} run: | for repo in meta_plugin_protocol meta_cli meta_core meta_git_lib loop_lib; do - if git clone --depth 1 -b "$BRANCH" "https://github.com/gitkb/${repo}.git" 2>/dev/null; then - echo "Cloned ${repo}@${BRANCH}" - elif git clone --depth 1 "https://github.com/gitkb/${repo}.git"; then - echo "Branch ${BRANCH} not found for ${repo}; falling back to default branch" + url="https://github.com/gitkb/${repo}.git" + # Exit code 2 means the branch does not exist; anything else is an error + status=0 + git ls-remote --exit-code --heads "$url" "$BRANCH" > /dev/null || status=$? + if [ "$status" -eq 0 ]; then + git clone --depth 1 -b "$BRANCH" "$url" + elif [ "$status" -eq 2 ]; then + echo "Branch ${BRANCH} not found for ${repo}; using the default branch" + git clone --depth 1 "$url" else - echo "::error::Failed to clone ${repo}" + echo "::error::Failed to look up ${repo}" exit 1 fi done From aa1c860776503e496bd3ceb659d577402a1e2684 Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:27:52 -0700 Subject: [PATCH 4/9] fix: project check/sync --recursive fail on a refused config Implements [[tasks/harmony-2749]] --- src/lib.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0d112e7..920506b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -264,12 +264,14 @@ fn execute_command_recursive( let mut all_missing: Vec<(String, String)> = Vec::new(); // Check the root meta config first + // A config that is refused is an error, not "nothing missing" if let Some((root_meta_path, _format)) = config::find_meta_config_in(cwd) { - if let Ok(projects) = parse_meta_projects(&root_meta_path) { - let missing = find_missing_projects(&projects, cwd); - for (name, url) in missing { - all_missing.push((name, url)); - } + let projects = match parse_meta_projects(&root_meta_path) { + Ok(projects) => projects, + Err(e) => return CommandResult::Error(format!("{e:#}")), + }; + for (name, url) in find_missing_projects(&projects, cwd) { + all_missing.push((name, url)); } } @@ -277,13 +279,14 @@ fn execute_command_recursive( for project_path in provided_projects { let project_dir = cwd.join(project_path); if let Some((nested_meta_path, _format)) = config::find_meta_config_in(&project_dir) { - if let Ok(projects) = parse_meta_projects(&nested_meta_path) { - let missing = find_missing_projects(&projects, &project_dir); - for (name, url) in missing { - // Use the full path relative to cwd - let full_path = format!("{project_path}/{name}"); - all_missing.push((full_path, url)); - } + let projects = match parse_meta_projects(&nested_meta_path) { + Ok(projects) => projects, + Err(e) => return CommandResult::Error(format!("{e:#}")), + }; + for (name, url) in find_missing_projects(&projects, &project_dir) { + // Use the full path relative to cwd + let full_path = format!("{project_path}/{name}"); + all_missing.push((full_path, url)); } } } From f6afc2df3c8f82b4230d3d5704162287845b8a18 Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:27:52 -0700 Subject: [PATCH 5/9] fix: escape the working directory in 'no .meta' errors Implements [[tasks/harmony-2749]] --- src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 920506b..f65407e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ //! Provides project management commands for meta repositories. use meta_cli::config::{self, MetaTreeNode, ProjectInfo}; -use meta_cli::display::escape; +use meta_cli::display::{escape, escape_path}; use meta_cli::worktree; use serde::Serialize; use std::borrow::Cow; @@ -125,7 +125,7 @@ pub fn execute_command( // Fall back to reading the local meta config let Some((meta_path, _format)) = config::find_meta_config_in(cwd) else { - return CommandResult::Error(format!("No .meta config found in {}", cwd.display())); + return CommandResult::Error(format!("No .meta config found in {}", escape_path(cwd))); }; let projects = match parse_meta_projects(&meta_path) { Ok(projects) => projects, @@ -336,7 +336,10 @@ fn handle_project_list(cwd: &Path, options: &ExecuteOptions) -> CommandResult { config::find_root_meta_dir(&nearest_meta_dir) } None => { - return CommandResult::Error(format!("No .meta config found in {}", cwd.display())) + return CommandResult::Error(format!( + "No .meta config found in {}", + escape_path(cwd) + )) } } } else { @@ -553,7 +556,7 @@ fn handle_project_dependents( // Find the root meta config let Some((nearest_meta_path, _)) = config::find_meta_config(cwd, None) else { - return CommandResult::Error(format!("No .meta config found in {}", cwd.display())); + return CommandResult::Error(format!("No .meta config found in {}", escape_path(cwd))); }; let nearest_meta_dir = nearest_meta_path.parent().unwrap_or(Path::new(".")); let start_dir = if options.recursive { @@ -563,7 +566,10 @@ fn handle_project_dependents( }; let Some((meta_path, _format)) = config::find_meta_config_in(&start_dir) else { - return CommandResult::Error(format!("No .meta config found in {}", start_dir.display())); + return CommandResult::Error(format!( + "No .meta config found in {}", + escape_path(&start_dir) + )); }; let (all_projects, _ignore) = match config::parse_meta_config(&meta_path) { From 5ab03ecfe8247778fac5501d54a420bc78433507 Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:27:52 -0700 Subject: [PATCH 6/9] ci: probe the exact branch ref, not one ending in the same name Implements [[tasks/harmony-2749]] --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cddf7a1..0e270d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: url="https://github.com/gitkb/${repo}.git" # Exit code 2 means the branch does not exist; anything else is an error status=0 - git ls-remote --exit-code --heads "$url" "$BRANCH" > /dev/null || status=$? + git ls-remote --exit-code --heads "$url" "refs/heads/$BRANCH" > /dev/null || status=$? if [ "$status" -eq 0 ]; then git clone --depth 1 -b "$BRANCH" "$url" elif [ "$status" -eq 2 ]; then @@ -91,7 +91,7 @@ jobs: url="https://github.com/gitkb/${repo}.git" # Exit code 2 means the branch does not exist; anything else is an error status=0 - git ls-remote --exit-code --heads "$url" "$BRANCH" > /dev/null || status=$? + git ls-remote --exit-code --heads "$url" "refs/heads/$BRANCH" > /dev/null || status=$? if [ "$status" -eq 0 ]; then git clone --depth 1 -b "$BRANCH" "$url" elif [ "$status" -eq 2 ]; then @@ -149,7 +149,7 @@ jobs: url="https://github.com/gitkb/${repo}.git" # Exit code 2 means the branch does not exist; anything else is an error status=0 - git ls-remote --exit-code --heads "$url" "$BRANCH" > /dev/null || status=$? + git ls-remote --exit-code --heads "$url" "refs/heads/$BRANCH" > /dev/null || status=$? if [ "$status" -eq 0 ]; then git clone --depth 1 -b "$BRANCH" "$url" elif [ "$status" -eq 2 ]; then From b2a243b702217ed735eca8df8aab27d2974df638 Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 18:56:39 -0700 Subject: [PATCH 7/9] fix: project update fails on a nested config it cannot read Implements [[tasks/harmony-2749]] --- src/lib.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f65407e..9f36acc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,7 +124,11 @@ pub fn execute_command( } // Fall back to reading the local meta config - let Some((meta_path, _format)) = config::find_meta_config_in(cwd) else { + let found = match config::find_meta_config_in(cwd) { + Ok(found) => found, + Err(e) => return CommandResult::Error(format!("{e:#}")), + }; + let Some((meta_path, _format)) = found else { return CommandResult::Error(format!("No .meta config found in {}", escape_path(cwd))); }; let projects = match parse_meta_projects(&meta_path) { @@ -265,7 +269,11 @@ fn execute_command_recursive( // Check the root meta config first // A config that is refused is an error, not "nothing missing" - if let Some((root_meta_path, _format)) = config::find_meta_config_in(cwd) { + let root = match config::find_meta_config_in(cwd) { + Ok(found) => found, + Err(e) => return CommandResult::Error(format!("{e:#}")), + }; + if let Some((root_meta_path, _format)) = root { let projects = match parse_meta_projects(&root_meta_path) { Ok(projects) => projects, Err(e) => return CommandResult::Error(format!("{e:#}")), @@ -278,7 +286,12 @@ fn execute_command_recursive( // Check each provided project directory for its own meta config for project_path in provided_projects { let project_dir = cwd.join(project_path); - if let Some((nested_meta_path, _format)) = config::find_meta_config_in(&project_dir) { + // One that can't be examined is an error, not "nothing missing" + let nested = match config::find_meta_config_in(&project_dir) { + Ok(found) => found, + Err(e) => return CommandResult::Error(format!("{e:#}")), + }; + if let Some((nested_meta_path, _format)) = nested { let projects = match parse_meta_projects(&nested_meta_path) { Ok(projects) => projects, Err(e) => return CommandResult::Error(format!("{e:#}")), @@ -565,7 +578,11 @@ fn handle_project_dependents( nearest_meta_dir.to_path_buf() }; - let Some((meta_path, _format)) = config::find_meta_config_in(&start_dir) else { + let found = match config::find_meta_config_in(&start_dir) { + Ok(found) => found, + Err(e) => return CommandResult::Error(format!("{e:#}")), + }; + let Some((meta_path, _format)) = found else { return CommandResult::Error(format!( "No .meta config found in {}", escape_path(&start_dir) From 11c5eb4b2b91905d94d3e28638958b6358528f23 Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 20:54:02 -0700 Subject: [PATCH 8/9] fix: a plain project check reads only the root config meta_cli sends the project list either way, so a non-empty list does not mean --recursive. Implements [[tasks/harmony-2749]] --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9f36acc..77d33b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,9 +117,10 @@ pub fn execute_command( return handle_project_list(cwd, &effective_options); } - // If we have provided projects from meta_cli (e.g., when --recursive is used), - // we need to check each project directory for missing repos in their .meta files - if !provided_projects.is_empty() { + // With --recursive, check each project directory meta_cli provided for + // missing repos in its own .meta (meta_cli sends the list either way; + // without --recursive only the root config counts) + if options.recursive && !provided_projects.is_empty() { return execute_command_recursive(command, options, provided_projects, cwd); } From cae8a52aee99bd43db3e9d7a7ffc4daf65f54999 Mon Sep 17 00:00:00 2001 From: gold-silver-copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Sun, 25 Oct 2026 21:09:52 -0700 Subject: [PATCH 9/9] fix: a plain project check uses the nearest workspace config, from a subdirectory too Implements [[tasks/harmony-2749]] --- src/lib.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 77d33b1..17d6bbd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,19 +124,17 @@ pub fn execute_command( return execute_command_recursive(command, options, provided_projects, cwd); } - // Fall back to reading the local meta config - let found = match config::find_meta_config_in(cwd) { - Ok(found) => found, - Err(e) => return CommandResult::Error(format!("{e:#}")), - }; - let Some((meta_path, _format)) = found else { + // The workspace's own config: the nearest one at or above cwd, as meta + // finds it (a config it can't read is returned, and reading it fails) + let Some((meta_path, _format)) = config::find_meta_config(cwd, None) else { return CommandResult::Error(format!("No .meta config found in {}", escape_path(cwd))); }; let projects = match parse_meta_projects(&meta_path) { Ok(projects) => projects, - Err(e) => return CommandResult::Error(format!("Failed to parse meta config: {e}")), + Err(e) => return CommandResult::Error(format!("Failed to parse meta config: {e:#}")), }; - let missing = find_missing_projects(&projects, cwd); + let root = meta_path.parent().unwrap_or(cwd); + let missing = find_missing_projects(&projects, root); match command { "project check" => { @@ -144,7 +142,7 @@ pub fn execute_command( CommandResult::Message("All projects are cloned and present.".to_string()) } else { // Print missing repos (uses visual formatting) - print_missing(&missing, cwd); + print_missing(&missing, root); CommandResult::Message(format!( "{} project(s) missing. Run 'meta git update' to clone them.", missing.len()