mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(vcs): Compare Directories copies nothing before the overwrite answer, filters nested folders, keeps name columns readable (#4120)
copy_merge without overwrite now finds the first conflict before writing anything, so declining the overwrite prompt leaves the destination untouched. A filter match below nested one-sided folders is attributed to the outermost one, the only row shown for that subtree. Name columns keep at least 96px; size and date shrink first and end in an ellipsis. Fixes #4084 Fixes #4085 Fixes #4086
This commit is contained in:
@@ -277,6 +277,25 @@ pub fn copy_merge(
|
||||
let target_base = project.filter(|p| to.starts_with(p)).or(Some(roots.1));
|
||||
let rules = Rules::new(from, source_base, excludes);
|
||||
let target_rules = Rules::new(to, target_base, excludes);
|
||||
// Find a conflict before writing anything, so declining to overwrite leaves the
|
||||
// destination untouched. Nothing below a missing destination can conflict.
|
||||
if !overwrite {
|
||||
let mut pending = vec![(from.to_path_buf(), to.to_path_buf())];
|
||||
while let Some((src, dst)) = pending.pop() {
|
||||
let meta = fs::symlink_metadata(&src)?;
|
||||
if rules.excluded(&src, meta.is_dir()) || target_rules.excluded(&dst, meta.is_dir()) {
|
||||
continue;
|
||||
}
|
||||
let Ok(existing) = fs::symlink_metadata(&dst) else { continue };
|
||||
if !(meta.is_dir() && existing.is_dir()) {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::AlreadyExists, dst.display().to_string()).into());
|
||||
}
|
||||
for entry in fs::read_dir(&src)? {
|
||||
let entry = entry?;
|
||||
pending.push((entry.path(), dst.join(entry.file_name())));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut pending = vec![(from.to_path_buf(), to.to_path_buf())];
|
||||
while let Some((src, dst)) = pending.pop() {
|
||||
let meta = fs::symlink_metadata(&src)?;
|
||||
@@ -494,6 +513,23 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_declined_overwrite_writes_nothing() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let left = tmp.path().join("left");
|
||||
let right = tmp.path().join("right");
|
||||
put(&left, "merge/a-clash.txt", b"source");
|
||||
put(&left, "merge/z-new.txt", b"source only");
|
||||
put(&left, "merge/deep/new.txt", b"new");
|
||||
put(&right, "merge/a-clash.txt", b"destination");
|
||||
let error =
|
||||
copy_merge(&left.join("merge"), &right.join("merge"), false, None, &[], (&left, &right)).unwrap_err();
|
||||
assert_eq!(error.kind, ErrorKind::AlreadyExists);
|
||||
assert_eq!(fs::read(right.join("merge/a-clash.txt")).unwrap(), b"destination");
|
||||
assert!(!right.join("merge/z-new.txt").exists());
|
||||
assert!(!right.join("merge/deep").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subtree_copy_keeps_excludes_anchored_to_each_comparison_root() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
background: var(--bg-editor);
|
||||
--compare-side: minmax(0, 1fr) 72px 132px;
|
||||
/* Names keep a readable width; size and date give way first in a narrow tab. */
|
||||
--compare-side: minmax(96px, 1fr) minmax(0, 72px) minmax(0, 132px);
|
||||
--compare-columns: var(--compare-side) 28px var(--compare-side);
|
||||
}
|
||||
.paths {
|
||||
@@ -118,15 +119,19 @@
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.num {
|
||||
justify-content: flex-end;
|
||||
text-align: right;
|
||||
/* Plain text cells: a narrow column ends in an ellipsis instead of clipping both edges. */
|
||||
.num,
|
||||
.date {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.num {
|
||||
text-align: right;
|
||||
}
|
||||
.date {
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.marker {
|
||||
justify-content: center;
|
||||
|
||||
@@ -96,9 +96,11 @@ export function directoryRows(
|
||||
const both = (e: DirectoryCompareEntry) => e.leftKind === "dir" && e.rightKind === "dir";
|
||||
const byPath = new Map(entries.map((e) => [e.path, e]));
|
||||
const oneSided = new Set(entries.filter((e) => directory(e) && (!e.leftKind || !e.rightKind)).map((e) => e.path));
|
||||
// The outermost one-sided folder: the only row shown for its whole subtree.
|
||||
const owner = (path: string) => {
|
||||
for (let p = parentOf(path); p; p = parentOf(p)) if (oneSided.has(p)) return p;
|
||||
return null;
|
||||
let found: string | null = null;
|
||||
for (let p = parentOf(path); p; p = parentOf(p)) if (oneSided.has(p)) found = p;
|
||||
return found;
|
||||
};
|
||||
const matched = new Set<string>();
|
||||
for (const e of entries) if (q && e.path.toLocaleLowerCase().includes(q)) matched.add(owner(e.path) ?? e.path);
|
||||
|
||||
@@ -116,6 +116,13 @@ describe("disk directory comparison", () => {
|
||||
"dir/sub/c.txt",
|
||||
]);
|
||||
expect(directoryRows(entries, all, "inside").map(label)).toEqual(["gone"]);
|
||||
// A match nested deeper inside a one-sided folder still shows that folder's row (#4085).
|
||||
const nested = [
|
||||
row("only-left", "leftOnly", "dir", null),
|
||||
row("only-left/sub", "leftOnly", "dir", null),
|
||||
row("only-left/sub/nested.txt", "leftOnly", "file", null),
|
||||
];
|
||||
expect(directoryRows(nested, new Set(["leftOnly"]), "nested.txt").map(label)).toEqual(["only-left"]);
|
||||
expect(directoryRows(entries, new Set(["rightOnly"]), "").map(label)).toEqual(["<dir/sub>", "dir/sub/c.txt"]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user