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
23 changes: 22 additions & 1 deletion .github/workflows/auto-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,32 @@ jobs:
# Use PAT to trigger downstream workflows; fallback to GITHUB_TOKEN
token: ${{ secrets.PARENT_REPO_PAT || github.token }}

- name: Clone dependencies
shell: bash
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
for repo in meta_core; do
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" "refs/heads/$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 look up ${repo}"
exit 1
fi
done

- name: Create workspace Cargo.toml
run: |
cat > Cargo.toml << 'EOF'
[workspace]
members = ["loop_lib"]
members = ["loop_lib", "meta_core"]
resolver = "2"

[workspace.package]
Expand Down
69 changes: 66 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,33 @@ jobs:
with:
path: loop_lib

- name: Clone dependencies
shell: bash
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
for repo in meta_core; do
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" "refs/heads/$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 look up ${repo}"
exit 1
fi
done

- name: Create workspace Cargo.toml
shell: bash
run: |
cat > Cargo.toml << 'EOF'
[workspace]
members = ["loop_lib"]
members = ["loop_lib", "meta_core"]
resolver = "2"

[workspace.package]
Expand Down Expand Up @@ -59,11 +80,32 @@ jobs:
with:
path: loop_lib

- name: Clone dependencies
shell: bash
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
for repo in meta_core; do
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" "refs/heads/$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 look up ${repo}"
exit 1
fi
done

- name: Create workspace Cargo.toml
run: |
cat > Cargo.toml << 'EOF'
[workspace]
members = ["loop_lib"]
members = ["loop_lib", "meta_core"]
resolver = "2"

[workspace.package]
Expand Down Expand Up @@ -96,11 +138,32 @@ jobs:
with:
path: loop_lib

- name: Clone dependencies
shell: bash
env:
BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
for repo in meta_core; do
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" "refs/heads/$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 look up ${repo}"
exit 1
fi
done

- name: Create workspace Cargo.toml
run: |
cat > Cargo.toml << 'EOF'
[workspace]
members = ["loop_lib"]
members = ["loop_lib", "meta_core"]
resolver = "2"

[workspace.package]
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ repository.workspace = true
description = "Core loop engine library for running commands across directories"

[dependencies]
# Any 0.x: child-repo CI builds meta_core as 0.0.0 or 0.1.0, releases as
# the workspace version
meta_core = { path = "../meta_core", version = "<1" }
anyhow = "1.0"
rayon = "1.5"
serde = { version = "1.0", features = ["derive"] }
Expand Down
21 changes: 13 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{Context, Result};
use colored::*;
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use meta_core::display::{escape, escape_path};
use rayon::prelude::*;
use rayon::ThreadPoolBuilder;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -201,8 +202,12 @@ pub fn add_aliases_to_global_looprc() -> Result<()> {
/// How a directory is named in progress and result lines: `.` for the root,
/// `./open-source/meta/loop_cli` for a directory under it, so repos that share
/// a basename stay distinguishable, and the full path for one outside it.
/// Without a root, the basename.
/// Without a root, the basename. Control characters in it are escaped.
fn display_name(dir: &Path, root: Option<&Path>) -> String {
escape(&plain_display_name(dir, root)).into_owned()
}

fn plain_display_name(dir: &Path, root: Option<&Path>) -> String {
let Some(root) = root else {
return dir
.file_name()
Expand Down Expand Up @@ -241,7 +246,7 @@ fn result_name(dir: &Path, root: Option<&Path>) -> String {
Some(dir.to_path_buf())
};
match base.as_deref().and_then(Path::file_name) {
Some(base) => format!(". ({})", base.to_string_lossy()),
Some(base) => format!(". ({})", escape(&base.to_string_lossy())),
None => name,
}
}
Expand Down Expand Up @@ -302,10 +307,10 @@ fn failed_result(dir: &Path, command: String, stderr: String) -> CommandResult {
fn dry_run_line(dir: &Path, command: &str) -> String {
let dir_display = if dir.as_os_str() == "." {
env::current_dir()
.map(|cwd| cwd.display().to_string())
.map(|cwd| escape_path(&cwd))
.unwrap_or_else(|_| ".".to_string())
} else {
dir.display().to_string()
escape_path(dir)
};
format!("Would execute in {dir_display}:\n {command}")
}
Expand All @@ -318,7 +323,7 @@ pub fn execute_command_in_directory(
extra_env: Option<&HashMap<String, String>>,
) -> CommandResult {
if !dir.exists() {
println!("\nNo directory found for {}", dir.display());
println!("\nNo directory found for {}", escape_path(dir));
println!(
"\x1b[31m\n✗ {}: No directory found. Command: {} (Exit code: {})\x1b[0m",
display_name(dir, config.root_dir.as_deref()),
Expand Down Expand Up @@ -356,7 +361,7 @@ pub fn execute_command_in_directory(
}

if config.verbose {
println!("Executing in directory: {}", dir.display());
println!("Executing in directory: {}", escape_path(dir));
}

if !config.silent {
Expand Down Expand Up @@ -422,7 +427,7 @@ pub fn execute_command_in_directory_capturing(
..failed_result(
dir,
display_command(argv),
format!("Directory does not exist: {}", dir.display()),
format!("Directory does not exist: {}", escape_path(dir)),
)
};
}
Expand Down Expand Up @@ -806,7 +811,7 @@ fn execute_commands_internal(config: &LoopConfig, commands: &[DirCommand]) -> Re
// Without a root the basename is ambiguous, so keep the full path
let name = match config.root_dir.as_deref() {
Some(root) => result_name(&result.directory, Some(root)),
None => result.directory.display().to_string(),
None => escape_path(&result.directory),
};
println!(
"\n{} {}: {} (Exit code {}) ",
Expand Down
15 changes: 15 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,18 @@ fn test_display_name_is_path_from_root() {
assert_eq!(display_name(Path::new("./repo"), None), "repo");
assert_eq!(result_name(root, Some(root)), ". (harmony)");
}

#[test]
fn test_display_names_escape_control_characters() {
let root = Path::new("/ws/x\u{1b}]0;TITLE\u{7}");
assert_eq!(result_name(root, Some(root)), ". (x\\u{1b}]0;TITLE\\u{7})");
assert_eq!(
display_name(&root.join("a\u{1b}[2J"), Some(root)),
"./a\\u{1b}[2J"
);
assert_eq!(
display_name(Path::new("/elsewhere/n\nfake"), Some(root)),
"/elsewhere/n\\nfake"
);
assert_eq!(display_name(Path::new("b\u{9b}31m"), None), "b\\u{9b}31m");
}
Loading