@d3ara1n/pi-editor-shell 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/git.test.ts +47 -0
- package/src/index.ts +5 -6
package/package.json
CHANGED
package/src/git.test.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
|
|
4
|
+
import { parseGitPorcelain } from "./index.ts";
|
|
5
|
+
|
|
6
|
+
describe("parseGitPorcelain", () => {
|
|
7
|
+
it("preserves the leading space of the first unstaged entry", () => {
|
|
8
|
+
assert.deepEqual(parseGitPorcelain(" M example.ts\n"), {
|
|
9
|
+
staged: 0,
|
|
10
|
+
unstaged: 1,
|
|
11
|
+
untracked: 0,
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("counts multiple unstaged entries without inventing a staged entry", () => {
|
|
16
|
+
assert.deepEqual(parseGitPorcelain(" M first.ts\n D second.ts\n"), {
|
|
17
|
+
staged: 0,
|
|
18
|
+
unstaged: 2,
|
|
19
|
+
untracked: 0,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("counts staged, unstaged, and untracked entries independently", () => {
|
|
24
|
+
const output = " M first.ts\nA added.ts\nMM both.ts\n?? new-directory/\n!! ignored.ts\n";
|
|
25
|
+
assert.deepEqual(parseGitPorcelain(output), {
|
|
26
|
+
staged: 2,
|
|
27
|
+
unstaged: 2,
|
|
28
|
+
untracked: 1,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("accepts output without a trailing newline", () => {
|
|
33
|
+
assert.deepEqual(parseGitPorcelain(" M example.ts"), {
|
|
34
|
+
staged: 0,
|
|
35
|
+
unstaged: 1,
|
|
36
|
+
untracked: 0,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("returns zero counts for empty output", () => {
|
|
41
|
+
assert.deepEqual(parseGitPorcelain(""), {
|
|
42
|
+
staged: 0,
|
|
43
|
+
unstaged: 0,
|
|
44
|
+
untracked: 0,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -217,15 +217,14 @@ interface GitDirty {
|
|
|
217
217
|
}
|
|
218
218
|
let _gitDirty: GitDirty | undefined;
|
|
219
219
|
|
|
220
|
-
/** Parse `git status --porcelain` output into staged, unstaged, and untracked counts.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (!lines) return { staged: 0, unstaged: 0, untracked: 0 };
|
|
224
|
-
|
|
220
|
+
/** Parse `git status --porcelain` output into staged, unstaged, and untracked counts.
|
|
221
|
+
* @internal — exported for testing. */
|
|
222
|
+
export function parseGitPorcelain(stdout: string): GitDirty {
|
|
225
223
|
let staged = 0;
|
|
226
224
|
let unstaged = 0;
|
|
227
225
|
let untracked = 0;
|
|
228
|
-
|
|
226
|
+
// Leading spaces encode the index status and must be preserved.
|
|
227
|
+
for (const line of stdout.split("\n")) {
|
|
229
228
|
if (line.length < 2) continue;
|
|
230
229
|
const x = line[0];
|
|
231
230
|
const y = line[1];
|