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
Show all changes
19 commits
Select commit Hold shift + click to select a range
72e6a88
fix(worktree): scope set removal to the workspace's repos
gold-silver-copper Oct 26, 2026
71151cf
fix(worktree): escape names in errors, read config via the shared res…
gold-silver-copper Oct 26, 2026
d771180
fix(config): propagate config lookup errors in worktree and git commands
gold-silver-copper Oct 26, 2026
bdcfa7c
fix(plugins): nested meta repos share their workspace's plugins
gold-silver-copper Oct 26, 2026
ac7b0d0
refactor(worktree): use meta_core's workspace and meta dir lookups
gold-silver-copper Oct 27, 2026
0b8e04f
refactor(worktree): record file name from meta_core
gold-silver-copper Oct 27, 2026
e5e3bed
fix(worktree): a set another workspace made is foreign, even in a sha…
gold-silver-copper Oct 27, 2026
ce4445a
refactor(worktree): Workspace::made_here is public for prune
gold-silver-copper Oct 27, 2026
4e1a3a1
fix(worktree): escape durations, --from-pr specs and branch names in …
gold-silver-copper Oct 27, 2026
b7d7ae7
fix(worktree): unknown ownership is not ours; escape the rest
gold-silver-copper Oct 27, 2026
4c2482d
fix(worktree): place set members at their path; name a gone workspace
gold-silver-copper Oct 27, 2026
7be1de3
fix(worktree): place_in_set compares resolved paths
gold-silver-copper Oct 27, 2026
6ac876f
fix(worktree): a set keeps a project's configured path, links included
gold-silver-copper Oct 27, 2026
76016da
fix(worktree): escape git's error text in worktree messages
gold-silver-copper Oct 27, 2026
b825179
feat(worktree): check a repo out where a link at its place leads
gold-silver-copper Oct 27, 2026
8144358
fix(worktree): escape the set name in 'No repos found'
gold-silver-copper Oct 28, 2026
856d5fb
feat(worktree): owner_dir, the meta dir whose settings a set's are
gold-silver-copper Oct 28, 2026
192c086
fix(worktree): hooks run in the directory of their config; escape the…
gold-silver-copper Oct 28, 2026
88b5d8f
refactor(worktree): resolve_worktree_root uses owner_dir
gold-silver-copper Oct 28, 2026
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
60 changes: 41 additions & 19 deletions src/worktree/git_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn ensure_checkout_config_is_not_bare(repo_path: &Path) -> Result<()> {
anyhow::bail!(
"Failed to inspect core.bare for '{}': {}",
escape_path(repo_path),
stderr.trim()
escape(stderr.trim())
);
}

Expand Down Expand Up @@ -106,9 +106,9 @@ pub fn git_worktree_add(
anyhow::bail!(
"git worktree add failed for '{}' (branch: {}, ref: {}): {}",
escape_path(repo_path),
branch,
ref_name,
stderr.trim()
escape(branch),
escape(ref_name),
escape(stderr.trim())
);
}
return Ok(Some(start)); // Always creates a new branch from ref
Expand Down Expand Up @@ -155,8 +155,8 @@ pub fn git_worktree_add(
anyhow::bail!(
"git worktree add failed for '{}' (branch: {}): {}",
escape_path(repo_path),
branch,
stderr.trim()
escape(branch),
escape(stderr.trim())
);
}

Expand All @@ -177,7 +177,7 @@ pub fn git_worktree_remove(repo_path: &Path, worktree_path: &Path, force: bool)

if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
anyhow::bail!("git worktree remove failed: {}", stderr.trim());
anyhow::bail!("git worktree remove failed: {}", escape(stderr.trim()));
}
Ok(())
}
Expand All @@ -194,7 +194,7 @@ pub fn git_status_summary(repo_path: &Path) -> Result<GitStatusSummary> {
anyhow::bail!(
"git status failed for '{}': {}",
escape_path(repo_path),
stderr.trim()
escape(stderr.trim())
);
}

Expand Down Expand Up @@ -337,9 +337,10 @@ pub fn git_rev_parse(repo_path: &Path, rev: &str) -> Result<Option<String>> {
return Ok(None);
}
anyhow::bail!(
"git rev-parse {rev} failed in {}: {}",
"git rev-parse {} failed in {}: {}",
escape(rev),
escape_path(repo_path),
stderr.trim()
escape(stderr.trim())
)
}

Expand All @@ -352,7 +353,7 @@ pub fn git_rev_parse(repo_path: &Path, rev: &str) -> Result<Option<String>> {
/// can't read is an error, not "free".
pub fn git_branch_is_free(repo_path: &Path, branch: &str) -> Result<()> {
let full = format!("refs/heads/{branch}");
let in_use = |by: &str| anyhow::anyhow!("'{branch}' is {by}");
let in_use = |by: &str| anyhow::anyhow!("'{}' is {by}", escape(branch));

// A symbolic branch would carry a ref transaction to the branch it points
// at, which this check never looked at.
Expand All @@ -363,8 +364,9 @@ pub fn git_branch_is_free(repo_path: &Path, branch: &str) -> Result<()> {
Some(1) => {}
Some(0) => return Err(in_use("a symbolic ref; meta only moves plain branches")),
_ => anyhow::bail!(
"Cannot inspect '{branch}': {}",
String::from_utf8_lossy(&symbolic.stderr).trim()
"Cannot inspect '{}': {}",
escape(branch),
escape(String::from_utf8_lossy(&symbolic.stderr).trim())
),
}

Expand All @@ -375,7 +377,7 @@ pub fn git_branch_is_free(repo_path: &Path, branch: &str) -> Result<()> {
list.status.success(),
"Cannot list the worktrees of {}: {}",
escape_path(repo_path),
String::from_utf8_lossy(&list.stderr).trim()
escape(String::from_utf8_lossy(&list.stderr).trim())
);
let wanted = format!("branch {full}");
if String::from_utf8_lossy(&list.stdout)
Expand All @@ -392,7 +394,7 @@ pub fn git_branch_is_free(repo_path: &Path, branch: &str) -> Result<()> {
output.status.success(),
"Cannot find the git directory of {}: {}",
escape_path(repo_path),
String::from_utf8_lossy(&output.stderr).trim()
escape(String::from_utf8_lossy(&output.stderr).trim())
);
// Relative output is relative to the repository, where git ran.
let common =
Expand Down Expand Up @@ -453,7 +455,7 @@ pub fn git_branch_is_free(repo_path: &Path, branch: &str) -> Result<()> {
/// through git's ref transaction.
pub fn git_delete_branch_at(repo_path: &Path, branch: &str, expected: &str) -> Result<()> {
git_branch_is_free(repo_path, branch)
.map_err(|e| anyhow::anyhow!("Branch '{branch}' is in use; kept ({e})"))?;
.map_err(|e| anyhow::anyhow!("Branch '{}' is in use; kept ({e})", escape(branch)))?;
let output = git_command(repo_path)
.args([
"update-ref",
Expand All @@ -466,8 +468,9 @@ pub fn git_delete_branch_at(repo_path: &Path, branch: &str, expected: &str) -> R
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
anyhow::bail!(
"Branch '{branch}' no longer points where it was created; kept ({})",
stderr.trim()
"Branch '{}' no longer points where it was created; kept ({})",
escape(branch),
escape(stderr.trim())
);
}
// Upstream settings of a deleted branch; there may be none.
Expand All @@ -486,7 +489,11 @@ pub fn git_fetch_branch(repo_path: &Path, branch: &str) -> Result<()> {

if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
anyhow::bail!("Failed to fetch branch '{}': {}", branch, stderr.trim());
anyhow::bail!(
"Failed to fetch branch '{}': {}",
escape(branch),
escape(stderr.trim())
);
}
Ok(())
}
Expand All @@ -496,6 +503,21 @@ mod tests {
use super::*;
use std::collections::BTreeSet;

#[test]
fn a_failed_fetch_is_reported_on_one_line() {
let tmp = init_git_repo();
git_command(tmp.path())
.args(["remote", "add", "origin", "/nonexistent/r\u{1b}[2J\nFORGED"])
.status()
.unwrap();
let err = git_fetch_branch(tmp.path(), "b\u{1b}[2J\nFORGED").unwrap_err();
let message = format!("{err:#}");
assert!(
!message.contains('\n') && !message.contains('\u{1b}'),
"{message}"
);
}

/// Create a minimal git repo in a tempdir and return the tempdir handle.
fn init_git_repo() -> tempfile::TempDir {
let tmp = tempfile::tempdir().unwrap();
Expand Down
Loading
Loading