fix: include untracked files in checkout shortstat (#608) (#762)

Count lines in untracked files when computing branch diffstat.
Adds file size limit, empty file handling, and CRLF normalization.
This commit is contained in:
Somasundaram Ayyappan
2026-05-05 21:10:54 +08:00
committed by GitHub
parent 425aa20747
commit 9f01b4b7a2
2 changed files with 83 additions and 5 deletions
@@ -459,6 +459,37 @@ const x = 1;
expect(shortstat).toEqual({ additions: 1, deletions: 0 });
});
it("includes untracked file lines in shortstat additions", async () => {
setupRemoteTrackingMain(repoDir, tempDir);
execSync("git checkout -b feature", { cwd: repoDir });
commitFile(repoDir, "committed.txt", "one\n", "add committed");
writeFileSync(join(repoDir, "untracked.txt"), "line1\nline2\nline3\n");
const shortstat = await getCheckoutShortstat(repoDir);
expect(shortstat).toEqual({ additions: 4, deletions: 0 });
});
it("reports untracked-only additions when no tracked changes exist", async () => {
setupRemoteTrackingMain(repoDir, tempDir);
writeFileSync(join(repoDir, "newfile.txt"), "a\nb\n");
const shortstat = await getCheckoutShortstat(repoDir);
expect(shortstat).toEqual({ additions: 2, deletions: 0 });
});
it("counts empty untracked files as 0 additions", async () => {
setupRemoteTrackingMain(repoDir, tempDir);
execSync("git checkout -b feature", { cwd: repoDir });
commitFile(repoDir, "committed.txt", "one\n", "add committed");
writeFileSync(join(repoDir, "empty.txt"), "");
const shortstat = await getCheckoutShortstat(repoDir);
expect(shortstat).toEqual({ additions: 1, deletions: 0 });
});
it("uses the merge-base for shortstat when a feature branch diverged from its tracked remote", async () => {
setupRemoteTrackingMain(repoDir, tempDir);
execSync("git checkout -b feature", { cwd: repoDir });