Archived
fix(git): render newly staged submodule pointer as new → <sha>
A staged submodule add records an all-zero head OID, which rendered as 0000000 → <sha>. Display the zero OID as "new" instead; the client pointer label needs no change (N4).
This commit is contained in:
@@ -151,6 +151,18 @@ describe("gitStatus with submodules", () => {
|
|||||||
expect(status.submodules).not.toContain("HARL");
|
expect(status.submodules).not.toContain("HARL");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("renders a newly staged submodule pointer as new → <sha> (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 () => {
|
it("prefixes oldPath with the submodule path for renames inside a submodule", async () => {
|
||||||
const { dir } = createFixture();
|
const { dir } = createFixture();
|
||||||
git(join(dir, "HARL"), ["mv", "a.txt", "renamed.txt"]);
|
git(join(dir, "HARL"), ["mv", "a.txt", "renamed.txt"]);
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ async function expandSubmodule(cwd: string, sub: SubmoduleRecord): Promise<{ fil
|
|||||||
path: sub.path,
|
path: sub.path,
|
||||||
index: sub.index,
|
index: sub.index,
|
||||||
workingTree: sub.workingTree,
|
workingTree: sub.workingTree,
|
||||||
submoduleFromCommit: short(sub.headOid),
|
submoduleFromCommit: displayFromCommit(sub.headOid),
|
||||||
submoduleToCommit: short(await resolveSubmoduleToCommit(cwd, sub)),
|
submoduleToCommit: short(await resolveSubmoduleToCommit(cwd, sub)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -284,6 +284,11 @@ function short(oid: string): string {
|
|||||||
return oid.slice(0, 7);
|
return oid.slice(0, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A newly staged submodule records an all-zero head OID; display the pointer as `new → <sha>`. */
|
||||||
|
function displayFromCommit(headOid: string): string {
|
||||||
|
return /^0+$/.test(headOid) ? "new" : short(headOid);
|
||||||
|
}
|
||||||
|
|
||||||
function hash(value: string): string {
|
function hash(value: string): string {
|
||||||
return createHash("sha1").update(value).digest("hex");
|
return createHash("sha1").update(value).digest("hex");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user