The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.
TypeScript code-editorcross-platformdapdatabase-clientdebuggerdesktop-appdeveloper-toolsgithttp-clientideintellijlsprusttauriterminal
feat(vcs): push notifications say how many commits went where (#961)
arookieofccc4ab5d4a8b2
diff --git a/src/features/vcs/__tests__/pushResult.test.ts b/src/features/vcs/__tests__/pushResult.test.tsnew file mode 100644index 000000000..4e1a73a43--- /dev/null+++ b/src/features/vcs/__tests__/pushResult.test.ts@@ -0,0 +1,69 @@+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import type { BranchInfo } from "@/bindings";++let branch: Partial<BranchInfo> = {};++vi.mock("@tauri-apps/api/core", async (importOriginal) => ({+ ...(await importOriginal<typeof import("@tauri-apps/api/core")>()),+ Channel: class {+ onmessage: (line: string) => void = () => {};+ },+}));++vi.mock("@/platform/ipc", async (importOriginal) => {+ const real = await importOriginal<typeof import("@/platform/ipc")>();+ return {+ ...real,+ commands: {+ ...real.commands,+ vcsBranchInfo: async () => ({+ status: "ok",+ data: { head: "main", headCommit: "c1", upstream: null, ahead: 0, behind: 0, operation: null, ...branch },+ }),+ vcsRemote: async () => ({ status: "ok", data: null }),+ cancelRequest: async () => ({ status: "ok", data: null }),+ },+ };+});++import { _resetI18nForTests, setLocale } from "@/platform/i18n";+import { provideNotificationService } from "@/workbench/contributions";+import { runRemote } from "../ops";++type Note = { title: string; level: string };+let notes: Note[] = [];++beforeEach(() => {+ notes = [];+ provideNotificationService({ notify: (n) => void notes.push(n as Note), expire: () => {} });+});++afterEach(() => {+ branch = {};+ _resetI18nForTests();+});++const pushTitle = async () => {+ expect(await runRemote({ op: "push" } as never, undefined, ["/p"])).toBe(true);+ return notes.at(-1)!.title;+};++describe("push result notification", () => {+ it("says how many commits went to which upstream", async () => {+ branch = { upstream: "origin/main", ahead: 3 };+ expect(await pushTitle()).toBe("Pushed 3 commits to origin/main");+ branch = { upstream: "origin/main", ahead: 1 };+ expect(await pushTitle()).toBe("Pushed 1 commit to origin/main");+ });++ it("stays generic when nothing was ahead", async () => {+ branch = { upstream: "origin/main", ahead: 0 };+ expect(await pushTitle()).toMatch(/successful$/);+ });++ it("is translated as a whole, count included", async () => {+ await setLocale("zh");+ branch = { upstream: "origin/main", ahead: 3 };+ expect(await pushTitle()).toBe("已推送 3 个提交到 origin/main");+ });+});diff --git a/src/features/vcs/ops.ts b/src/features/vcs/ops.tsindex c76fb17bb..8e81fd0c2 100644--- a/src/features/vcs/ops.ts+++ b/src/features/vcs/ops.ts@@ -188,6 +188,7 @@ export async function runRemote(// repositories that have nothing to pull from (detached HEAD, e.g. submodules; no upstream).const failures: string[] = [];const updated: UpdatedRange[] = [];+ const pushed: Array<{ to: string; commits: number }> = [];for (const repo of repos) {const name = repos.length > 1 && repo ? repoName(repo) : null;if (name) logConsole("info", name);@@ -200,6 +201,12 @@ export async function runRemote(}try {const before = op.op === "pull" || op.op === "pullFrom" ? await headCommit(repo) : null;+ // The push summary counts what the push carries: the commits the branch is+ // ahead of its upstream before the push (pushing does not move the local head).+ if (op.op === "push" || (op.op === "pushBranch" && !op.target)) {+ const info = await call(commands.vcsBranchInfo(repo)).catch(() => null);+ if (info?.upstream && info.ahead > 0) pushed.push({ to: info.upstream, commits: info.ahead });+ }await call(commands.vcsRemote(repo, request, op, channel));const after = before ? await headCommit(repo) : null;if (before && after && before !== after) updated.push({ repo, from: before, to: after });@@ -212,14 +219,17 @@ export async function runRemote(if (failures.length) throw new Error(failures.join("\n"));lastRemoteError = null;if (op.op === "pull" || op.op === "pullFrom") await notifyUpdated(updated);- else+ else {+ // One repository's push names what went out; a partial multi-repo push stays generic.+ const one = pushed.length === 1 ? pushed[0] : null;notifications().notify({group: "vcs",level: "info",key: "vcs.remote",- title: `${doneTitle} successful`,+ title: one ? pushedTitle(one.commits, one.to) : `${doneTitle} successful`,body: lastLine && !/%/.test(lastLine) ? lastLine : undefined,});+ }return true;} catch (e) {const cancelled = isCancelled(e);@@ -258,6 +268,10 @@ const headCommit = (repo: string | null) =>const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? "" : "s"}`;+/** "Pushed 3 commits to origin/main", translated per count. */+const pushedTitle = (n: number, to: string) =>+ n === 1 ? tx`Pushed ${n} commit to ${to}` : tx`Pushed ${n} commits to ${to}`;+/** IDEA's Update Project result: "N files updated in M commits" with View Commits. */async function notifyUpdated(updated: readonly UpdatedRange[]) {if (!updated.length) {diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.jsonindex 5891763c5..2e00073a9 100644--- a/src/platform/locales/text/zh.json+++ b/src/platform/locales/text/zh.json@@ -4114,6 +4114,8 @@"Rebasing {n} commit from the root": "正在从根变基 {n} 个提交","Rebasing {n} commits from the root": "正在从根变基 {n} 个提交","Push Commits to {remote}": "推送提交到 {remote}",+ "Pushed {n} commit to {remote}": "已推送 {n} 个提交到 {remote}",+ "Pushed {n} commits to {remote}": "已推送 {n} 个提交到 {remote}","You're going to force push to '{target}'. It may overwrite commits at the remote. Are you sure you want to proceed?": "您将强制推送到 '{target}'。这可能会覆盖远程上的提交。确定要继续吗?","Delete “{name}” from the shelf? This cannot be undone.": "是否从搁置中删除“{name}”?此操作无法撤消。","Handler for {keystroke}": "{keystroke} 的处理程序",