From f3582403f3413c828ba4ebafbc29170a37180fdd Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Sat, 5 Dec 2026 00:21:44 +0900 Subject: [PATCH] fix(svn): show each working copy's svn update output in the console (#8065) Update Project over several working copies only showed the first one's output: every repository's vcs_remote call shared one Tauri channel, and a channel stops delivering once its command ends. Each command now gets its own channel (also for the multi-repository Git branch update). The Subversion backend streams svn update's own lines (Updating, the U/A/D/C/G file lines, Updated to revision N) instead of a single summary line. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- crates/ide-host/tests/svn.rs | 50 ++++++++++++ crates/ide-svn/src/backend.rs | 7 +- crates/ide-svn/src/ops.rs | 14 +++- crates/ide-svn/tests/working_copy.rs | 6 +- .../vcs/__tests__/updateConsoleOutput.test.ts | 76 +++++++++++++++++++ src/features/vcs/ops.ts | 26 ++++--- 6 files changed, 163 insertions(+), 16 deletions(-) create mode 100644 src/features/vcs/__tests__/updateConsoleOutput.test.ts diff --git a/crates/ide-host/tests/svn.rs b/crates/ide-host/tests/svn.rs index 4fb52004ae..22ef18d49d 100644 --- a/crates/ide-host/tests/svn.rs +++ b/crates/ide-host/tests/svn.rs @@ -1565,3 +1565,53 @@ async fn remote_browser_export_checkout_options_and_restricted_mode() { .unwrap_err(); assert_eq!(del_err.kind, ide_core::error::ErrorKind::Unavailable, "{del_err:?}"); } + +/// Update Project in two working copies (issue #7433): the console gets svn's own output for +/// each, the files it changed and the revision reached, not only a summary line. +#[tokio::test] +async fn update_output_of_two_working_copies() { + let Some(fx) = fixture() else { return }; + let seed = fx.checkout("seed"); + for name in ["a.txt", "gone.txt"] { + std::fs::write(seed.join(name), "one\n").unwrap(); + } + fx.svn(&seed, &["add", "-q", "a.txt", "gone.txt"]); + fx.svn(&seed, &["commit", "-q", "-m", "seed"]); + let project_root = fx.base.join("project"); + std::fs::create_dir(&project_root).unwrap(); + let trunk = format!("{}/trunk", fx.url); + for name in ["boot", "antd"] { + fx.svn(&fx.base, &["checkout", "-q", &trunk, project_root.join(name).to_str().unwrap()]); + } + std::fs::write(seed.join("a.txt"), "two\n").unwrap(); + std::fs::write(seed.join("new.txt"), "new\n").unwrap(); + fx.svn(&seed, &["add", "-q", "new.txt"]); + fx.svn(&seed, &["rm", "-q", "gone.txt"]); + fx.svn(&seed, &["commit", "-q", "-m", "two"]); + + let host = Host::new(common::host_config(&fx.base)).with_subversion(false); + host.trust.decide(&project_root, true, false).unwrap(); + let project = host.open_project("main", &project_root).unwrap(); + until("both working copies", || project.backends().len() == 2).await; + for name in ["boot", "antd"] { + let lines = Arc::new(std::sync::Mutex::new(Vec::::new())); + let sink = lines.clone(); + let channel = ide_host::ops::Channel::new(move |line: String| sink.lock().unwrap().push(line)); + let op = vcs::RemoteOp::UpdateProjectBranch { rebase: false }; + let repo = Some(project_root.join(name)); + vcs::vcs_remote(&host, "main", repo, ide_core::RequestId::next(), op, channel, None).await.unwrap(); + let lines = lines.lock().unwrap().clone(); + let changed: Vec<&str> = lines + .iter() + .filter_map(|l| { + l.split_once(char::is_whitespace).filter(|(code, _)| code.len() == 1).map(|(_, p)| p.trim()) + }) + .map(|p| p.rsplit(['/', '\\']).next().unwrap()) + .collect(); + assert!(lines.iter().any(|l| l.starts_with("Updating ")), "{name}: {lines:?}"); + for file in ["a.txt", "new.txt", "gone.txt"] { + assert!(changed.contains(&file), "{name}: {file} in {lines:?}"); + } + assert!(lines.last().is_some_and(|l| l.starts_with("Updated to revision ")), "{name}: {lines:?}"); + } +} diff --git a/crates/ide-svn/src/backend.rs b/crates/ide-svn/src/backend.rs index af3933e248..a0dc7545d4 100644 --- a/crates/ide-svn/src/backend.rs +++ b/crates/ide-svn/src/backend.rs @@ -1347,11 +1347,10 @@ impl Backend for WorkingCopy { } /// Update Project, Update File / Update Directory: `svn update` of the whole working copy - /// or of `paths`. Conflicts stay for the merge editor. + /// or of `paths`, its output (the files it changed, the revision reached) sent to `output`. + /// Conflicts stay for the merge editor. fn update(&self, paths: &[PathBuf], cancel: &CancellationToken, output: &dyn Fn(String)) -> IdeResult { - let (revision, changed) = WorkingCopy::update_counted(self, paths, None, cancel)?; - output(format!("Updated to revision {revision}.")); - Ok(changed) + WorkingCopy::update_reporting(self, paths, None, cancel, output).map(|(_, changed)| changed) } fn branches(&self) -> IdeResult> { diff --git a/crates/ide-svn/src/ops.rs b/crates/ide-svn/src/ops.rs index 22b7c68002..4b302b82f3 100644 --- a/crates/ide-svn/src/ops.rs +++ b/crates/ide-svn/src/ops.rs @@ -374,10 +374,22 @@ impl WorkingCopy { paths: &[PathBuf], revision: Option<&str>, cancel: &CancellationToken, + ) -> IdeResult<(u64, usize)> { + self.update_reporting(paths, revision, cancel, &|_| {}) + } + + /// [`update_counted`](Self::update_counted), with each line svn prints (`Updating '.':`, + /// `U src/a.rs`, `Updated to revision 7.`) passed to `on_line` as it comes. + pub fn update_reporting( + &self, + paths: &[PathBuf], + revision: Option<&str>, + cancel: &CancellationToken, + on_line: &dyn Fn(String), ) -> IdeResult<(u64, usize)> { let mut argv = args(["update", "--accept", "postpone", "-r", revision.unwrap_or("HEAD")]); argv.extend(targets(&self.paths_or_root(paths)?)); - let out = String::from_utf8_lossy(&self.remote(&argv, Some(cancel))?).into_owned(); + let out = String::from_utf8_lossy(&self.remote_streaming(&argv, Some(cancel), on_line)?).into_owned(); let _ = self.refresh(); let reached = reached_revision(&out) .ok_or_else(|| IdeError::internal(format!("unexpected `svn update` output: {out}")))?; diff --git a/crates/ide-svn/tests/working_copy.rs b/crates/ide-svn/tests/working_copy.rs index 4ce13cbba5..53ab80baa2 100644 --- a/crates/ide-svn/tests/working_copy.rs +++ b/crates/ide-svn/tests/working_copy.rs @@ -459,7 +459,11 @@ fn lines_of_development_properties_locks_and_changelists() { let lines = std::sync::Mutex::new(Vec::new()); Backend::update(&wc, &[], &cancel, &|line| lines.lock().unwrap().push(line)).unwrap(); assert_eq!(std::fs::read_to_string(&a).unwrap(), "from other\n"); - assert_eq!(lines.into_inner().unwrap(), ["Updated to revision 5."]); + // svn's own output, the file it changed included. + let lines = lines.into_inner().unwrap(); + assert!(lines.first().is_some_and(|l| l.starts_with("Updating ")), "{lines:?}"); + assert!(lines.iter().any(|l| l.starts_with("U ") && l.ends_with("a.txt")), "{lines:?}"); + assert_eq!(lines.last().map(String::as_str), Some("Updated to revision 5.")); // Properties. wc.set_property(&a, "review", Some("needed\nby ann")).unwrap(); diff --git a/src/features/vcs/__tests__/updateConsoleOutput.test.ts b/src/features/vcs/__tests__/updateConsoleOutput.test.ts new file mode 100644 index 0000000000..5a136ca268 --- /dev/null +++ b/src/features/vcs/__tests__/updateConsoleOutput.test.ts @@ -0,0 +1,76 @@ +/** + * Issue #7433: Update Project in several working copies shows every update's output in the + * console. A Tauri channel stops delivering once the command it was given to ends, so each + * repository's command needs its own channel. + */ +import { afterEach, describe, expect, it, vi } from "vitest"; +import type { RemoteOp } from "@/bindings"; + +/** As Tauri's Channel: the backend ends it with the command, and later lines never arrive. */ +const { EndingChannel } = vi.hoisted(() => ({ + EndingChannel: class { + ended = false; + constructor(public onmessage: (line: string) => void = () => {}) {} + }, +})); +type EndingChannel = InstanceType; + +/** What svn prints for each working copy. */ +const OUTPUT: Record = { + "/w/boot": ["Updating '.':", "U src/a.ts", "Updated to revision 22537."], + "/w/antd": ["Updating '.':", "A lib/new.ts", "D lib/old.ts", "Updated to revision 22537."], + "/w/sapp": ["Updating '.':", "C app/conflict.ts", "Updated to revision 22537."], +}; + +vi.mock("@tauri-apps/api/core", async (importOriginal) => ({ + ...(await importOriginal()), + Channel: EndingChannel, +})); + +vi.mock("@/platform/ipc", async (importOriginal) => { + const real = await importOriginal(); + return { + ...real, + commands: { + ...real.commands, + vcsRemote: async (repo: string | null, _request: unknown, _op: RemoteOp, channel: EndingChannel) => { + for (const line of OUTPUT[repo ?? ""] ?? []) if (!channel.ended) channel.onmessage(line); + channel.ended = true; + return { status: "ok", data: null }; + }, + vcsBranchInfo: async () => ({ status: "error", error: { kind: "invalid", message: "not Git" } }), + vcsMergeBase: async () => ({ status: "error", error: { kind: "invalid", message: "not Git" } }), + vcsFinishShelfBatch: async () => ({ status: "ok", data: null }), + cancelRequest: async () => ({ status: "ok", data: null }), + }, + }; +}); + +import { provideNotificationService } from "@/workbench/contributions"; +import { runRemoteRound, useVcsConsole } from "../ops"; +import { useVcs } from "../store"; + +afterEach(() => useVcs.setState({ roots: [], root: null, kinds: {}, remoteBusy: null })); + +describe("Update Project output in the console", () => { + it("shows svn's output for every working copy, not only the first", async () => { + provideNotificationService({ notify: () => {}, expire: () => {} }); + const roots = Object.keys(OUTPUT); + useVcs.setState({ roots, root: "/w", kinds: Object.fromEntries(roots.map((r) => [r, "subversion"])) }); + const earlier = useVcsConsole.getState().lines.length; + const op = { op: "updateProjectBranch", rebase: false } as const; + await runRemoteRound(roots.map((repo) => ({ repo, op }))); + const lines = useVcsConsole + .getState() + .lines.slice(earlier) + .map(({ text }) => text); + expect(lines).toEqual([ + "svn update (boot)", + ...OUTPUT["/w/boot"]!, + "svn update (antd)", + ...OUTPUT["/w/antd"]!, + "svn update (sapp)", + ...OUTPUT["/w/sapp"]!, + ]); + }); +}); diff --git a/src/features/vcs/ops.ts b/src/features/vcs/ops.ts index c49990a808..4b0fa9a9f0 100644 --- a/src/features/vcs/ops.ts +++ b/src/features/vcs/ops.ts @@ -303,6 +303,14 @@ function pushedBranch(op: RemoteOp) { return null; } +/** + * A new channel for each command, all passing their lines to `onLine`: a channel ends with + * the command it was given to, so the next repository's output would never arrive on it. + */ +function channelFor(onLine: (line: string) => void): () => Channel { + return () => new Channel(onLine); +} + /** Runs one group under the same progress and cancellation, retaining each failed repository's error. */ export async function runRemoteRound( targets: readonly RemoteTarget[], @@ -341,14 +349,13 @@ export async function runRemoteRound( sticky: true, actions: [{ label: "Cancel", run: cancelRemote }], }); - const channel = new Channel(); let lastLine = ""; - channel.onmessage = (line) => { + const output = channelFor((line) => { logConsole("out", line); const text = line.trim(); if (text && text !== "Done") lastLine = text; task(text || null, progressFraction(text), false); - }; + }); const shelfBatch = startShelfBatch( targets.map((target) => target.repo), isUpdate(first), @@ -473,8 +480,8 @@ export async function runRemoteRound( if (cancelRequested || useProject.getState().project !== project) break; const remoteOp = op.op === "fetchRemote" || (op.op === "fetch" && !op.background) ? { ...op, report: true } : op; - // oxlint-disable-next-line no-await-in-loop -- remote commands share one request/channel and run in repository order - const report = await call(commands.vcsRemote(repo, request, remoteOp, channel, shelfBatch.id)); + // oxlint-disable-next-line no-await-in-loop -- remote commands share one request and run in repository order + const report = await call(commands.vcsRemote(repo, request, remoteOp, output(), shelfBatch.id)); if (report && "remotes" in report) { hasFetchReport = true; const errors = report.remotes.flatMap((result) => { @@ -697,11 +704,10 @@ export async function runBranchUpdates( sticky: true, actions: [{ label: "Cancel", run: cancelRemote }], }); - const channel = new Channel(); - channel.onmessage = (line) => { + const output = channelFor((line) => { logConsole("out", line); task(line.trim() || null, false); - }; + }); const results: RepoBranchUpdate[] = []; try { const incoming = cancelIncomingCheck(); @@ -710,8 +716,8 @@ export async function runBranchUpdates( if (cancelled || useProject.getState().project !== project) break; logConsole("cmd", `git update ${names.join(" ")}${repo && branches.size > 1 ? ` (${repoName(repo)})` : ""}`); try { - // oxlint-disable-next-line no-await-in-loop -- branch updates share one request/channel and cancellation, so repositories run in turn - const updates = await call(commands.vcsUpdateBranches(repo, request, [...names], channel, null)); + // oxlint-disable-next-line no-await-in-loop -- branch updates share one request and cancellation, so repositories run in turn + const updates = await call(commands.vcsUpdateBranches(repo, request, [...names], output(), null)); results.push(...updates.map((u) => ({ ...u, repo }))); } catch (error) { if (isCancelled(error)) throw error;