@narumitw/pi-starship 0.55.0 → 0.55.2
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/README.md +21 -36
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
- package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
- package/dist/chunks/commands-ATILSUVK.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +38 -53
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
- package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +588 -618
- package/src/config.ts +580 -660
- package/src/effective-config.ts +46 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +101 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +57 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +22 -24
- package/src/modules/render.ts +124 -140
- package/src/modules/thinking.ts +27 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +125 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -571
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- package/dist/chunks/package-LG5H7BBM.js.map +0 -7
|
@@ -2,414 +2,379 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
GitBranchSnapshot,
|
|
6
|
+
GitCommitSnapshot,
|
|
7
|
+
GitMetricsSnapshot,
|
|
8
|
+
GitSnapshot,
|
|
9
|
+
GitStateSnapshot,
|
|
10
|
+
GitStatusSnapshot,
|
|
11
|
+
GitWorktreeSnapshot,
|
|
12
12
|
} from "../types.js";
|
|
13
13
|
|
|
14
14
|
const GIT_TIMEOUT_MS = 3_000;
|
|
15
15
|
|
|
16
16
|
export interface ReadGitSnapshotOptions {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
includeMetrics: boolean;
|
|
18
|
+
includeTag: boolean;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export async function readGitSnapshot(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
pi: ExtensionAPI,
|
|
24
|
+
cwd: string,
|
|
25
|
+
options: ReadGitSnapshotOptions,
|
|
26
26
|
): Promise<GitSnapshot | undefined> {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
...parsed,
|
|
80
|
-
root: metadata?.root,
|
|
81
|
-
commit,
|
|
82
|
-
state: metadata ? parseGitState(metadata.gitDirectory) : undefined,
|
|
83
|
-
metrics,
|
|
84
|
-
worktree: metadata?.worktree,
|
|
85
|
-
};
|
|
27
|
+
const statusPromise = pi.exec(
|
|
28
|
+
"git",
|
|
29
|
+
["--no-optional-locks", "status", "--porcelain=v2", "--branch", "--show-stash", "--untracked-files=normal"],
|
|
30
|
+
{ cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
|
|
31
|
+
);
|
|
32
|
+
const metadataPromise = pi.exec(
|
|
33
|
+
"git",
|
|
34
|
+
["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
|
|
35
|
+
{ cwd, signal: options.signal, timeout: GIT_TIMEOUT_MS },
|
|
36
|
+
);
|
|
37
|
+
const metricsPromise = options.includeMetrics
|
|
38
|
+
? pi.exec("git", ["--no-optional-locks", "diff", "--shortstat", "HEAD", "--"], {
|
|
39
|
+
cwd,
|
|
40
|
+
signal: options.signal,
|
|
41
|
+
timeout: GIT_TIMEOUT_MS,
|
|
42
|
+
})
|
|
43
|
+
: Promise.resolve(undefined);
|
|
44
|
+
const tagPromise = options.includeTag
|
|
45
|
+
? pi.exec("git", ["describe", "--tags", "--exact-match", "HEAD"], {
|
|
46
|
+
cwd,
|
|
47
|
+
signal: options.signal,
|
|
48
|
+
timeout: GIT_TIMEOUT_MS,
|
|
49
|
+
})
|
|
50
|
+
: Promise.resolve(undefined);
|
|
51
|
+
|
|
52
|
+
const [statusResult, metadataResult, metricsResult, tagResult] = await Promise.all([
|
|
53
|
+
statusPromise,
|
|
54
|
+
metadataPromise,
|
|
55
|
+
metricsPromise,
|
|
56
|
+
tagPromise,
|
|
57
|
+
]);
|
|
58
|
+
if (statusResult.code !== 0 || statusResult.killed) return undefined;
|
|
59
|
+
|
|
60
|
+
const parsed = parseGitStatusPorcelainV2(statusResult.stdout);
|
|
61
|
+
const metadata =
|
|
62
|
+
metadataResult.code === 0 && !metadataResult.killed ? parseGitRepositoryMetadata(metadataResult.stdout) : undefined;
|
|
63
|
+
const commit = withTag(parsed.commit, tagResult);
|
|
64
|
+
const metrics =
|
|
65
|
+
metricsResult && metricsResult.code === 0 && !metricsResult.killed
|
|
66
|
+
? parseGitDiffShortstat(metricsResult.stdout)
|
|
67
|
+
: undefined;
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
...parsed,
|
|
71
|
+
root: metadata?.root,
|
|
72
|
+
commit,
|
|
73
|
+
state: metadata ? parseGitState(metadata.gitDirectory) : undefined,
|
|
74
|
+
metrics,
|
|
75
|
+
worktree: metadata?.worktree,
|
|
76
|
+
};
|
|
86
77
|
}
|
|
87
78
|
|
|
88
|
-
export async function readGitStatus(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"status",
|
|
97
|
-
"--porcelain=v2",
|
|
98
|
-
"--branch",
|
|
99
|
-
"--show-stash",
|
|
100
|
-
"--untracked-files=normal",
|
|
101
|
-
],
|
|
102
|
-
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
103
|
-
);
|
|
104
|
-
if (result.code !== 0 || result.killed) return undefined;
|
|
105
|
-
return parseGitStatusPorcelainV2(result.stdout).status;
|
|
79
|
+
export async function readGitStatus(pi: ExtensionAPI, cwd: string): Promise<GitStatusSnapshot | undefined> {
|
|
80
|
+
const result = await pi.exec(
|
|
81
|
+
"git",
|
|
82
|
+
["--no-optional-locks", "status", "--porcelain=v2", "--branch", "--show-stash", "--untracked-files=normal"],
|
|
83
|
+
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
84
|
+
);
|
|
85
|
+
if (result.code !== 0 || result.killed) return undefined;
|
|
86
|
+
return parseGitStatusPorcelainV2(result.stdout).status;
|
|
106
87
|
}
|
|
107
88
|
|
|
108
|
-
export async function readGitWorktree(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
);
|
|
117
|
-
if (result.code !== 0 || result.killed) return undefined;
|
|
118
|
-
return parseGitRepositoryMetadata(result.stdout)?.worktree;
|
|
89
|
+
export async function readGitWorktree(pi: ExtensionAPI, cwd: string): Promise<GitWorktreeSnapshot | undefined> {
|
|
90
|
+
const result = await pi.exec(
|
|
91
|
+
"git",
|
|
92
|
+
["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
|
|
93
|
+
{ cwd, timeout: GIT_TIMEOUT_MS },
|
|
94
|
+
);
|
|
95
|
+
if (result.code !== 0 || result.killed) return undefined;
|
|
96
|
+
return parseGitRepositoryMetadata(result.stdout)?.worktree;
|
|
119
97
|
}
|
|
120
98
|
|
|
121
99
|
interface ParsedGitStatus {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
100
|
+
branch?: GitBranchSnapshot;
|
|
101
|
+
commit?: GitCommitSnapshot;
|
|
102
|
+
status: GitStatusSnapshot;
|
|
125
103
|
}
|
|
126
104
|
|
|
127
105
|
export function parseGitStatusPorcelainV2(output: string): ParsedGitStatus {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
106
|
+
const status = emptyGitStatus();
|
|
107
|
+
let branchName: string | undefined;
|
|
108
|
+
let commitHash: string | undefined;
|
|
109
|
+
let upstream: string | undefined;
|
|
110
|
+
|
|
111
|
+
for (const line of output.split(/\r?\n/u)) {
|
|
112
|
+
if (!line) continue;
|
|
113
|
+
if (line.startsWith("# branch.oid ")) {
|
|
114
|
+
const value = line.slice("# branch.oid ".length).trim();
|
|
115
|
+
if (value && value !== "(initial)") commitHash = value;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (line.startsWith("# branch.head ")) {
|
|
119
|
+
branchName = line.slice("# branch.head ".length).trim();
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (line.startsWith("# branch.upstream ")) {
|
|
123
|
+
upstream = line.slice("# branch.upstream ".length).trim();
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (line.startsWith("# branch.ab ")) {
|
|
127
|
+
const match = /^# branch\.ab \+(\d+) -(\d+)$/u.exec(line);
|
|
128
|
+
status.ahead = match?.[1] ? Number(match[1]) : 0;
|
|
129
|
+
status.behind = match?.[2] ? Number(match[2]) : 0;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (line.startsWith("# stash ")) {
|
|
133
|
+
const count = Number(line.slice("# stash ".length));
|
|
134
|
+
status.stashed = Number.isSafeInteger(count) && count > 0 ? count : 0;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
addPorcelainV2Status(status, line);
|
|
138
|
+
}
|
|
139
|
+
finalizeStatus(status);
|
|
140
|
+
|
|
141
|
+
const detached = branchName === "(detached)";
|
|
142
|
+
const remote = splitUpstream(upstream);
|
|
143
|
+
const branch = branchName
|
|
144
|
+
? {
|
|
145
|
+
name: detached ? "HEAD" : branchName,
|
|
146
|
+
...remote,
|
|
147
|
+
detached,
|
|
148
|
+
}
|
|
149
|
+
: undefined;
|
|
150
|
+
const commit = commitHash ? { hash: commitHash, detached } : undefined;
|
|
151
|
+
return { branch, commit, status };
|
|
174
152
|
}
|
|
175
153
|
|
|
176
154
|
export function parseGitStatusPorcelain(output: string): GitStatusSnapshot {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
155
|
+
const status = emptyGitStatus();
|
|
156
|
+
for (const line of output.split(/\r?\n/u)) {
|
|
157
|
+
if (!line) continue;
|
|
158
|
+
if (line.startsWith("## ")) {
|
|
159
|
+
const ahead = /\bahead (\d+)/u.exec(line);
|
|
160
|
+
const behind = /\bbehind (\d+)/u.exec(line);
|
|
161
|
+
status.ahead = ahead?.[1] ? Number(ahead[1]) : 0;
|
|
162
|
+
status.behind = behind?.[1] ? Number(behind[1]) : 0;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const indexStatus = line[0] ?? " ";
|
|
166
|
+
const worktreeStatus = line[1] ?? " ";
|
|
167
|
+
if (indexStatus === "?" && worktreeStatus === "?") {
|
|
168
|
+
status.untracked += 1;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (isConflict(indexStatus, worktreeStatus)) {
|
|
172
|
+
status.conflicted += 1;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
addNormalStatus(status, indexStatus, worktreeStatus);
|
|
176
|
+
if (indexStatus === "R" || indexStatus === "C") status.renamed += 1;
|
|
177
|
+
}
|
|
178
|
+
finalizeStatus(status);
|
|
179
|
+
return status;
|
|
202
180
|
}
|
|
203
181
|
|
|
204
182
|
export function parseGitDiffShortstat(output: string): GitMetricsSnapshot {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
183
|
+
return {
|
|
184
|
+
added: parseShortstatMetric(output, "insertion(+)", "insertions(+)") ?? 0,
|
|
185
|
+
deleted: parseShortstatMetric(output, "deletion(-)", "deletions(-)") ?? 0,
|
|
186
|
+
};
|
|
209
187
|
}
|
|
210
188
|
|
|
211
|
-
function parseShortstatMetric(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const count = Number(countText);
|
|
227
|
-
return Number.isSafeInteger(count) ? count : undefined;
|
|
228
|
-
}
|
|
229
|
-
return undefined;
|
|
189
|
+
function parseShortstatMetric(output: string, singularLabel: string, pluralLabel: string): number | undefined {
|
|
190
|
+
for (const field of output.split(",")) {
|
|
191
|
+
const trimmed = field.trim();
|
|
192
|
+
const separator = trimmed.indexOf(" ");
|
|
193
|
+
if (separator <= 0) continue;
|
|
194
|
+
const label = trimmed.slice(separator + 1).trimStart();
|
|
195
|
+
if (label !== singularLabel && label !== pluralLabel) continue;
|
|
196
|
+
const countText = trimmed.slice(0, separator);
|
|
197
|
+
for (const character of countText) {
|
|
198
|
+
if (character < "0" || character > "9") return undefined;
|
|
199
|
+
}
|
|
200
|
+
const count = Number(countText);
|
|
201
|
+
return Number.isSafeInteger(count) ? count : undefined;
|
|
202
|
+
}
|
|
203
|
+
return undefined;
|
|
230
204
|
}
|
|
231
205
|
|
|
232
206
|
export function parseGitState(gitDirectory: string): GitStateSnapshot | undefined {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return undefined;
|
|
207
|
+
const rebaseMerge = join(gitDirectory, "rebase-merge");
|
|
208
|
+
if (existsSync(rebaseMerge)) return operationWithProgress("REBASING", rebaseMerge, "msgnum", "end");
|
|
209
|
+
|
|
210
|
+
const rebaseApply = join(gitDirectory, "rebase-apply");
|
|
211
|
+
if (existsSync(rebaseApply)) {
|
|
212
|
+
const state = existsSync(join(rebaseApply, "applying"))
|
|
213
|
+
? "AM"
|
|
214
|
+
: existsSync(join(rebaseApply, "rebasing"))
|
|
215
|
+
? "REBASING"
|
|
216
|
+
: "AM/REBASE";
|
|
217
|
+
return operationWithProgress(state, rebaseApply, "next", "last");
|
|
218
|
+
}
|
|
219
|
+
if (existsSync(join(gitDirectory, "MERGE_HEAD"))) return { state: "MERGING" };
|
|
220
|
+
if (existsSync(join(gitDirectory, "REVERT_HEAD"))) return { state: "REVERTING" };
|
|
221
|
+
if (existsSync(join(gitDirectory, "CHERRY_PICK_HEAD"))) return { state: "CHERRY-PICKING" };
|
|
222
|
+
if (existsSync(join(gitDirectory, "BISECT_LOG"))) return { state: "BISECTING" };
|
|
223
|
+
return undefined;
|
|
251
224
|
}
|
|
252
225
|
|
|
253
226
|
interface GitRepositoryMetadata {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
227
|
+
root: string;
|
|
228
|
+
gitDirectory: string;
|
|
229
|
+
worktree?: GitWorktreeSnapshot;
|
|
257
230
|
}
|
|
258
231
|
|
|
259
232
|
function parseGitRepositoryMetadata(output: string): GitRepositoryMetadata | undefined {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
: { name: basename(path) || path, path },
|
|
271
|
-
};
|
|
233
|
+
const lines = output.trimEnd().split(/\r?\n/u);
|
|
234
|
+
if (lines.length !== 3) return undefined;
|
|
235
|
+
const [path, commonDir, gitDirectory] = lines;
|
|
236
|
+
if (!path || !commonDir || !gitDirectory) return undefined;
|
|
237
|
+
if (![path, commonDir, gitDirectory].every(isAbsolute)) return undefined;
|
|
238
|
+
return {
|
|
239
|
+
root: path,
|
|
240
|
+
gitDirectory,
|
|
241
|
+
worktree: samePath(commonDir, gitDirectory) ? undefined : { name: basename(path) || path, path },
|
|
242
|
+
};
|
|
272
243
|
}
|
|
273
244
|
|
|
274
245
|
export function parseGitWorktree(output: string): GitWorktreeSnapshot | undefined {
|
|
275
|
-
|
|
246
|
+
return parseGitRepositoryMetadata(output)?.worktree;
|
|
276
247
|
}
|
|
277
248
|
|
|
278
249
|
function addPorcelainV2Status(status: GitStatusSnapshot, line: string) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
250
|
+
const kind = line[0];
|
|
251
|
+
if (kind === "?") {
|
|
252
|
+
status.untracked += 1;
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (kind === "u") {
|
|
256
|
+
status.conflicted += 1;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (kind !== "1" && kind !== "2") return;
|
|
260
|
+
const indexStatus = line[2] ?? ".";
|
|
261
|
+
const worktreeStatus = line[3] ?? ".";
|
|
262
|
+
addNormalStatus(status, indexStatus, worktreeStatus);
|
|
263
|
+
if (kind === "2") status.renamed += 1;
|
|
293
264
|
}
|
|
294
265
|
|
|
295
266
|
function addNormalStatus(status: GitStatusSnapshot, indexStatus: string, worktreeStatus: string) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
267
|
+
if (indexStatus === "A") status.indexAdded += 1;
|
|
268
|
+
if (indexStatus === "D") status.indexDeleted += 1;
|
|
269
|
+
if (indexStatus === "M") status.indexModified += 1;
|
|
270
|
+
if (indexStatus === "T") status.indexTypechanged += 1;
|
|
271
|
+
if (worktreeStatus === "A") status.worktreeAdded += 1;
|
|
272
|
+
if (worktreeStatus === "D") status.worktreeDeleted += 1;
|
|
273
|
+
if (worktreeStatus === "M") status.worktreeModified += 1;
|
|
274
|
+
if (worktreeStatus === "T") status.worktreeTypechanged += 1;
|
|
304
275
|
}
|
|
305
276
|
|
|
306
277
|
function finalizeStatus(status: GitStatusSnapshot) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
278
|
+
status.deleted = status.worktreeDeleted + status.indexDeleted;
|
|
279
|
+
status.modified = status.worktreeModified + status.worktreeAdded;
|
|
280
|
+
status.staged = status.indexModified + status.indexAdded + status.indexTypechanged;
|
|
281
|
+
status.typechanged = status.worktreeTypechanged;
|
|
311
282
|
}
|
|
312
283
|
|
|
313
284
|
function emptyGitStatus(): GitStatusSnapshot {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
285
|
+
return {
|
|
286
|
+
ahead: 0,
|
|
287
|
+
behind: 0,
|
|
288
|
+
stashed: 0,
|
|
289
|
+
conflicted: 0,
|
|
290
|
+
deleted: 0,
|
|
291
|
+
renamed: 0,
|
|
292
|
+
modified: 0,
|
|
293
|
+
staged: 0,
|
|
294
|
+
typechanged: 0,
|
|
295
|
+
untracked: 0,
|
|
296
|
+
worktreeAdded: 0,
|
|
297
|
+
worktreeDeleted: 0,
|
|
298
|
+
worktreeModified: 0,
|
|
299
|
+
worktreeTypechanged: 0,
|
|
300
|
+
indexAdded: 0,
|
|
301
|
+
indexDeleted: 0,
|
|
302
|
+
indexModified: 0,
|
|
303
|
+
indexTypechanged: 0,
|
|
304
|
+
};
|
|
334
305
|
}
|
|
335
306
|
|
|
336
307
|
function splitUpstream(upstream: string | undefined): {
|
|
337
|
-
|
|
338
|
-
|
|
308
|
+
remoteName?: string;
|
|
309
|
+
remoteBranch?: string;
|
|
339
310
|
} {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
311
|
+
if (!upstream) return {};
|
|
312
|
+
const separator = upstream.indexOf("/");
|
|
313
|
+
if (separator <= 0 || separator === upstream.length - 1) return { remoteBranch: upstream };
|
|
314
|
+
return {
|
|
315
|
+
remoteName: upstream.slice(0, separator),
|
|
316
|
+
remoteBranch: upstream.slice(separator + 1),
|
|
317
|
+
};
|
|
347
318
|
}
|
|
348
319
|
|
|
349
320
|
function withTag(
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
321
|
+
commit: GitCommitSnapshot | undefined,
|
|
322
|
+
result:
|
|
323
|
+
| {
|
|
324
|
+
stdout: string;
|
|
325
|
+
code: number;
|
|
326
|
+
killed: boolean;
|
|
327
|
+
}
|
|
328
|
+
| undefined,
|
|
358
329
|
): GitCommitSnapshot | undefined {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
330
|
+
if (!commit || !result || result.code !== 0 || result.killed) return commit;
|
|
331
|
+
const tag = result.stdout.trim();
|
|
332
|
+
return tag ? { ...commit, tag: tag.split(/\r?\n/u)[0] } : commit;
|
|
362
333
|
}
|
|
363
334
|
|
|
364
335
|
function operationWithProgress(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
336
|
+
state: string,
|
|
337
|
+
directory: string,
|
|
338
|
+
currentName: string,
|
|
339
|
+
totalName: string,
|
|
369
340
|
): GitStateSnapshot {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
341
|
+
const progressCurrent = readPositiveInteger(join(directory, currentName));
|
|
342
|
+
const progressTotal = readPositiveInteger(join(directory, totalName));
|
|
343
|
+
return progressCurrent !== undefined && progressTotal !== undefined
|
|
344
|
+
? { state, progressCurrent, progressTotal }
|
|
345
|
+
: { state };
|
|
375
346
|
}
|
|
376
347
|
|
|
377
348
|
function readPositiveInteger(path: string): number | undefined {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
349
|
+
try {
|
|
350
|
+
const value = Number(readFileSync(path, "utf8").trim());
|
|
351
|
+
return Number.isSafeInteger(value) && value > 0 ? value : undefined;
|
|
352
|
+
} catch {
|
|
353
|
+
return undefined;
|
|
354
|
+
}
|
|
384
355
|
}
|
|
385
356
|
|
|
386
357
|
function samePath(left: string, right: string): boolean {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
358
|
+
const normalizedLeft = resolve(left);
|
|
359
|
+
const normalizedRight = resolve(right);
|
|
360
|
+
return process.platform === "win32"
|
|
361
|
+
? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase()
|
|
362
|
+
: normalizedLeft === normalizedRight;
|
|
392
363
|
}
|
|
393
364
|
|
|
394
365
|
function isConflict(indexStatus: string, worktreeStatus: string): boolean {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
366
|
+
return (
|
|
367
|
+
(indexStatus === "D" && worktreeStatus === "D") ||
|
|
368
|
+
(indexStatus === "A" && worktreeStatus === "A") ||
|
|
369
|
+
indexStatus === "U" ||
|
|
370
|
+
worktreeStatus === "U"
|
|
371
|
+
);
|
|
401
372
|
}
|
|
402
373
|
|
|
403
|
-
export function gitStatusEqual(
|
|
404
|
-
|
|
405
|
-
right: GitStatusSnapshot | undefined,
|
|
406
|
-
): boolean {
|
|
407
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
374
|
+
export function gitStatusEqual(left: GitStatusSnapshot | undefined, right: GitStatusSnapshot | undefined): boolean {
|
|
375
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
408
376
|
}
|
|
409
377
|
|
|
410
|
-
export function gitSnapshotEqual(
|
|
411
|
-
|
|
412
|
-
right: GitSnapshot | undefined,
|
|
413
|
-
): boolean {
|
|
414
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
378
|
+
export function gitSnapshotEqual(left: GitSnapshot | undefined, right: GitSnapshot | undefined): boolean {
|
|
379
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
415
380
|
}
|