From 65a20b59fe6a09730ce244e3fdc3d8a1f6d56f13 Mon Sep 17 00:00:00 2001 From: Federico Jaramillo Martinez Date: Fri, 24 Jul 2026 11:56:54 +0200 Subject: [PATCH] =?UTF-8?q?fix(git):=20render=20newly=20staged=20submodule?= =?UTF-8?q?=20pointer=20as=20new=20=E2=86=92=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A staged submodule add records an all-zero head OID, which rendered as 0000000 → . Display the zero OID as "new" instead; the client pointer label needs no change (N4). --- src/server/git/gitService.test.ts | 12 ++++++++++++ src/server/git/gitService.ts | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/server/git/gitService.test.ts b/src/server/git/gitService.test.ts index c1dce50..2be94e4 100644 --- a/src/server/git/gitService.test.ts +++ b/src/server/git/gitService.test.ts @@ -151,6 +151,18 @@ describe("gitStatus with submodules", () => { expect(status.submodules).not.toContain("HARL"); }); + it("renders a newly staged submodule pointer as new → (zero head OID)", async () => { + const { dir, c2 } = createFixture(); + git(dir, ["submodule", "add", join(dir, "..", "origin"), "NEWSUB"]); // staged add: `1 A. S...` with a zero head OID + + const status = await gitStatus(dir); + const pointer = status.files.find((file) => file.path === "NEWSUB"); + expect(pointer?.index).toBe("added"); + expect(pointer?.submoduleFromCommit).toBe("new"); + expect(pointer?.submoduleToCommit).toBe(c2.slice(0, 7)); + expect(status.submodules).toContain("NEWSUB"); + }); + it("prefixes oldPath with the submodule path for renames inside a submodule", async () => { const { dir } = createFixture(); git(join(dir, "HARL"), ["mv", "a.txt", "renamed.txt"]); diff --git a/src/server/git/gitService.ts b/src/server/git/gitService.ts index 8bf33bb..718a55f 100644 --- a/src/server/git/gitService.ts +++ b/src/server/git/gitService.ts @@ -85,7 +85,7 @@ async function expandSubmodule(cwd: string, sub: SubmoduleRecord): Promise<{ fil path: sub.path, index: sub.index, workingTree: sub.workingTree, - submoduleFromCommit: short(sub.headOid), + submoduleFromCommit: displayFromCommit(sub.headOid), submoduleToCommit: short(await resolveSubmoduleToCommit(cwd, sub)), }); } @@ -284,6 +284,11 @@ function short(oid: string): string { return oid.slice(0, 7); } +/** A newly staged submodule records an all-zero head OID; display the pointer as `new → `. */ +function displayFromCommit(headOid: string): string { + return /^0+$/.test(headOid) ? "new" : short(headOid); +} + function hash(value: string): string { return createHash("sha1").update(value).digest("hex"); }