@lifo-sh/core 0.2.0 → 0.3.0

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.
Files changed (106) hide show
  1. package/dist/awk-B6L8oRkp.js +123 -0
  2. package/dist/{basename-C2v8jn7p.js → basename-CgA_lsvv.js} +1 -1
  3. package/dist/{cat-B2exoWlk.js → cat-UKg6GIpI.js} +1 -1
  4. package/dist/{chmod-CQS63aP7.js → chmod-DHB58pfa.js} +1 -1
  5. package/dist/{chown-rgGwZwu9.js → chown-D1bGwvZd.js} +1 -1
  6. package/dist/commands/registry.d.ts.map +1 -1
  7. package/dist/commands/text/awk.d.ts.map +1 -1
  8. package/dist/commands/text/cut.d.ts.map +1 -1
  9. package/dist/commands/text/diff.d.ts.map +1 -1
  10. package/dist/commands/text/grep.d.ts.map +1 -1
  11. package/dist/commands/text/head.d.ts.map +1 -1
  12. package/dist/commands/text/nl.d.ts.map +1 -1
  13. package/dist/commands/text/rev.d.ts.map +1 -1
  14. package/dist/commands/text/sed.d.ts.map +1 -1
  15. package/dist/commands/text/sort.d.ts.map +1 -1
  16. package/dist/commands/text/tail.d.ts.map +1 -1
  17. package/dist/commands/text/uniq.d.ts.map +1 -1
  18. package/dist/commands/text/wc.d.ts.map +1 -1
  19. package/dist/commands/vcs/git.d.ts +4 -0
  20. package/dist/commands/vcs/git.d.ts.map +1 -0
  21. package/dist/{cp-C8mNek36.js → cp-hsOMjGjb.js} +1 -1
  22. package/dist/cut-BxA2sLod.js +65 -0
  23. package/dist/diff-BgH1-ECz.js +150 -0
  24. package/dist/{dirname-BY_Gu5i2.js → dirname-BsNcj76E.js} +1 -1
  25. package/dist/{du-D25egSeK.js → du-Dz7i5Bf4.js} +1 -1
  26. package/dist/{file-BPs1dqg5.js → file-CiWscEov.js} +1 -1
  27. package/dist/{find-CRUAXbhO.js → find-CWXxOQ3D.js} +1 -1
  28. package/dist/git-mHSHRpnj.js +603 -0
  29. package/dist/{grep-B9pTCSNY.js → grep-BQsxs32R.js} +33 -26
  30. package/dist/gunzip-DF-BdBEb.js +47 -0
  31. package/dist/{gzip-DgE-9PzE.js → gzip-lYiTGRe_.js} +4 -5
  32. package/dist/head-BtcClCUM.js +53 -0
  33. package/dist/{index-DccAPaZF.js → index-Do_xqri5.js} +2574 -1285
  34. package/dist/index.d.ts +9 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +58 -45
  37. package/dist/kernel/index.d.ts +2 -1
  38. package/dist/kernel/index.d.ts.map +1 -1
  39. package/dist/kernel/persistence/PersistenceManager.d.ts +3 -1
  40. package/dist/kernel/persistence/PersistenceManager.d.ts.map +1 -1
  41. package/dist/kernel/persistence/backends.d.ts +22 -0
  42. package/dist/kernel/persistence/backends.d.ts.map +1 -0
  43. package/dist/kernel/persistence/index.d.ts +6 -0
  44. package/dist/kernel/persistence/index.d.ts.map +1 -0
  45. package/dist/kernel/persistence/serializer.d.ts +8 -0
  46. package/dist/kernel/persistence/serializer.d.ts.map +1 -1
  47. package/dist/kernel/storage/BlobStore.d.ts +31 -0
  48. package/dist/kernel/storage/BlobStore.d.ts.map +1 -0
  49. package/dist/kernel/storage/ContentStore.d.ts +52 -0
  50. package/dist/kernel/storage/ContentStore.d.ts.map +1 -0
  51. package/dist/kernel/storage/index.d.ts +7 -0
  52. package/dist/kernel/storage/index.d.ts.map +1 -0
  53. package/dist/kernel/vfs/VFS.d.ts +31 -3
  54. package/dist/kernel/vfs/VFS.d.ts.map +1 -1
  55. package/dist/kernel/vfs/index.d.ts +4 -1
  56. package/dist/kernel/vfs/index.d.ts.map +1 -1
  57. package/dist/kernel/vfs/providers/NativeFsProvider.d.ts +63 -0
  58. package/dist/kernel/vfs/providers/NativeFsProvider.d.ts.map +1 -0
  59. package/dist/kernel/vfs/types.d.ts +27 -0
  60. package/dist/kernel/vfs/types.d.ts.map +1 -1
  61. package/dist/{ls-BiT10kLm.js → ls-BX03h4IP.js} +1 -1
  62. package/dist/{mkdir-DgzJ2JLj.js → mkdir-DGGZuAyh.js} +1 -1
  63. package/dist/{mktemp-Sh5DWxvc.js → mktemp-C537o9DE.js} +1 -1
  64. package/dist/{mv-Kp6DjQ8n.js → mv-46W3dEtX.js} +1 -1
  65. package/dist/{nl-DBLFdpfC.js → nl-vZH6hOSG.js} +13 -10
  66. package/dist/node-compat/buffer.d.ts +29 -2
  67. package/dist/node-compat/buffer.d.ts.map +1 -1
  68. package/dist/node-compat/fs.d.ts +62 -0
  69. package/dist/node-compat/fs.d.ts.map +1 -1
  70. package/dist/{realpath-BOeYN6nD.js → realpath-Ubp4BElh.js} +1 -1
  71. package/dist/rev-Dqg_gF2D.js +39 -0
  72. package/dist/{rm-DA2w3xTR.js → rm-FnbVRwGK.js} +1 -1
  73. package/dist/{rmdir-BiGbNDOT.js → rmdir-B2a-CeUJ.js} +3 -3
  74. package/dist/sandbox/Sandbox.d.ts +31 -0
  75. package/dist/sandbox/Sandbox.d.ts.map +1 -1
  76. package/dist/sandbox/SandboxFs.d.ts +4 -0
  77. package/dist/sandbox/SandboxFs.d.ts.map +1 -1
  78. package/dist/sandbox/types.d.ts +19 -0
  79. package/dist/sandbox/types.d.ts.map +1 -1
  80. package/dist/sed-BHijDEOD.js +95 -0
  81. package/dist/{sort-CSzSGTdB.js → sort-CheGhnUV.js} +19 -14
  82. package/dist/{stat-D0i1gTKB.js → stat-YSBnw2tJ.js} +1 -1
  83. package/dist/tail-9Z1OE7L7.js +52 -0
  84. package/dist/{tar-DkyzTzmT.js → tar-Dc-wpdQT.js} +15 -16
  85. package/dist/{tee-RqoZ3qG-.js → tee-C4QkabXH.js} +1 -1
  86. package/dist/{touch-k2NomRzL.js → touch-BeFpZeqv.js} +1 -1
  87. package/dist/{tree-B_j2_PsZ.js → tree-BiBsUSQR.js} +1 -1
  88. package/dist/uniq-BeGU0UTU.js +54 -0
  89. package/dist/{unzip-FwYCTDEZ.js → unzip-SUXLk4bS.js} +18 -19
  90. package/dist/utils/mime.d.ts +4 -0
  91. package/dist/utils/mime.d.ts.map +1 -0
  92. package/dist/wc-BLupYdzi.js +69 -0
  93. package/dist/{wget-2NAABIHc.js → wget-ALEPUtGk.js} +1 -1
  94. package/dist/{zip--0ncHv0q.js → zip-V6SMbx7b.js} +11 -12
  95. package/package.json +5 -2
  96. package/dist/archive-nRHWNwjH.js +0 -192
  97. package/dist/awk-CchAsBzt.js +0 -118
  98. package/dist/cut-BZez9bS1.js +0 -60
  99. package/dist/diff-tWPvmikU.js +0 -129
  100. package/dist/gunzip-BYlJhPf7.js +0 -48
  101. package/dist/head-DzP_T5Wx.js +0 -48
  102. package/dist/rev-CWRUIXWp.js +0 -34
  103. package/dist/sed-ClWZ06zX.js +0 -90
  104. package/dist/tail-tcIJLQnB.js +0 -47
  105. package/dist/uniq-hzJnHQOm.js +0 -51
  106. package/dist/wc-Jp7nOops.js +0 -60
@@ -0,0 +1,603 @@
1
+ import { r as g, k as S, n as E } from "./index-Do_xqri5.js";
2
+ typeof globalThis.Buffer > "u" && (globalThis.Buffer = E);
3
+ let y;
4
+ async function A() {
5
+ return y || (y = (await import("isomorphic-git")).default), y;
6
+ }
7
+ function T(n) {
8
+ function e(r) {
9
+ const t = n.stat(r), s = t.type === "directory" ? 16384 : t.mode & 511 | 32768;
10
+ return {
11
+ type: t.type,
12
+ mode: s,
13
+ size: t.size,
14
+ mtimeMs: t.mtime,
15
+ ctimeMs: t.ctime,
16
+ uid: 1e3,
17
+ gid: 1e3,
18
+ ino: 0,
19
+ dev: 0,
20
+ isFile: () => t.type === "file",
21
+ isDirectory: () => t.type === "directory",
22
+ isSymbolicLink: () => !1
23
+ };
24
+ }
25
+ function a(r) {
26
+ const t = S(r);
27
+ t === "/" || t === "." || n.exists(t) || (a(t), n.mkdir(t));
28
+ }
29
+ return { promises: {
30
+ async readFile(r, t) {
31
+ const s = typeof t == "string" ? t : t == null ? void 0 : t.encoding;
32
+ return s === "utf8" || s === "utf-8" ? n.readFileString(r) : E.from(n.readFile(r));
33
+ },
34
+ async writeFile(r, t, s) {
35
+ a(r);
36
+ const f = typeof t == "string" ? t : new Uint8Array(t);
37
+ n.writeFile(r, f);
38
+ },
39
+ async unlink(r) {
40
+ n.unlink(r);
41
+ },
42
+ async readdir(r) {
43
+ return n.readdir(r).map((t) => t.name);
44
+ },
45
+ async mkdir(r, t) {
46
+ t != null && t.recursive ? n.mkdir(r, { recursive: !0 }) : n.mkdir(r);
47
+ },
48
+ async rmdir(r) {
49
+ n.rmdir(r);
50
+ },
51
+ async stat(r) {
52
+ return e(r);
53
+ },
54
+ async lstat(r) {
55
+ return e(r);
56
+ },
57
+ async readlink(r) {
58
+ throw Object.assign(new Error(`ENOENT: readlink '${r}'`), { code: "ENOENT" });
59
+ },
60
+ async symlink(r, t) {
61
+ },
62
+ async chmod(r, t) {
63
+ }
64
+ } };
65
+ }
66
+ function m() {
67
+ return {
68
+ async request({ url: n, method: e, headers: a, body: i }) {
69
+ let r;
70
+ if (i) {
71
+ const d = [];
72
+ for await (const c of i)
73
+ d.push(c);
74
+ const u = d.reduce((c, w) => c + w.length, 0);
75
+ r = new Uint8Array(u);
76
+ let o = 0;
77
+ for (const c of d)
78
+ r.set(c, o), o += c.length;
79
+ }
80
+ const t = await fetch(n, {
81
+ method: e || "GET",
82
+ headers: a,
83
+ body: r
84
+ }), s = {};
85
+ t.headers.forEach((d, u) => {
86
+ s[u] = d;
87
+ });
88
+ const f = new Uint8Array(await t.arrayBuffer());
89
+ async function* l() {
90
+ yield f;
91
+ }
92
+ return {
93
+ url: t.url,
94
+ method: e || "GET",
95
+ headers: s,
96
+ body: l(),
97
+ statusCode: t.status,
98
+ statusMessage: t.statusText
99
+ };
100
+ }
101
+ };
102
+ }
103
+ function h(n, e) {
104
+ let a = g("/", e);
105
+ for (; ; ) {
106
+ if (n.exists(a + "/.git") || n.exists(a + "/.git/HEAD"))
107
+ return a;
108
+ if (a === "/") return null;
109
+ a = S(a);
110
+ }
111
+ }
112
+ const v = `usage: git <command> [<args>]
113
+
114
+ Commands:
115
+ init Create an empty Git repository
116
+ clone Clone a repository
117
+ add Add file contents to the index
118
+ commit Record changes to the repository
119
+ status Show the working tree status
120
+ log Show commit logs
121
+ branch List, create, or delete branches
122
+ checkout Switch branches or restore files
123
+ diff Show changes between commits
124
+ remote Manage remote repositories
125
+ push Update remote refs along with objects
126
+ pull Fetch from and integrate with a remote
127
+ fetch Download objects and refs from a remote
128
+ `;
129
+ async function B(n, e, a) {
130
+ const i = e.args[0] ? g(e.cwd, e.args[0]) : e.cwd;
131
+ return await n.init({ fs: a, dir: i }), e.stdout.write(`Initialized empty Git repository in ${i}/.git/
132
+ `), 0;
133
+ }
134
+ async function _(n, e, a) {
135
+ const i = e.args[0];
136
+ if (!i)
137
+ return e.stderr.write(`fatal: You must specify a repository to clone.
138
+ `), 128;
139
+ let r = e.args[1];
140
+ if (!r) {
141
+ const t = i.replace(/\.git$/, "").split("/");
142
+ r = t[t.length - 1] || "repo";
143
+ }
144
+ r = g(e.cwd, r), e.stdout.write(`Cloning into '${r}'...
145
+ `);
146
+ try {
147
+ return await n.clone({
148
+ fs: a,
149
+ http: m(),
150
+ dir: r,
151
+ url: i,
152
+ singleBranch: !0,
153
+ depth: 1,
154
+ corsProxy: void 0
155
+ }), e.stdout.write(`done.
156
+ `), 0;
157
+ } catch (t) {
158
+ return e.stderr.write(`fatal: ${t instanceof Error ? t.message : String(t)}
159
+ `), 128;
160
+ }
161
+ }
162
+ async function I(n, e, a) {
163
+ if (e.args.length === 0)
164
+ return e.stderr.write(`Nothing specified, nothing added.
165
+ `), 1;
166
+ const i = h(e.vfs, e.cwd);
167
+ for (const r of e.args)
168
+ if (r === ".")
169
+ await p(n, e.vfs, a, i, e.cwd);
170
+ else {
171
+ const t = R(e.cwd, i, r);
172
+ try {
173
+ e.vfs.exists(g(i, t)) ? e.vfs.stat(g(i, t)).type === "directory" ? await p(n, e.vfs, a, i, g(i, t)) : await n.add({ fs: a, dir: i, filepath: t }) : await n.remove({ fs: a, dir: i, filepath: t });
174
+ } catch (s) {
175
+ return e.stderr.write(`fatal: ${s instanceof Error ? s.message : String(s)}
176
+ `), 128;
177
+ }
178
+ }
179
+ return 0;
180
+ }
181
+ async function p(n, e, a, i, r) {
182
+ const t = e.readdir(r);
183
+ for (const s of t) {
184
+ const f = r + "/" + s.name;
185
+ if (s.name !== ".git")
186
+ if (s.type === "directory")
187
+ await p(n, e, a, i, f);
188
+ else {
189
+ const l = f.slice(i.length + 1);
190
+ await n.add({ fs: a, dir: i, filepath: l });
191
+ }
192
+ }
193
+ }
194
+ function R(n, e, a) {
195
+ const i = g(n, a);
196
+ return i.startsWith(e + "/") ? i.slice(e.length + 1) : i.startsWith("/") ? i.slice(1) : i;
197
+ }
198
+ async function k(n, e, a) {
199
+ const i = h(e.vfs, e.cwd);
200
+ let r;
201
+ for (let t = 0; t < e.args.length; t++)
202
+ if ((e.args[t] === "-m" || e.args[t] === "--message") && e.args[t + 1]) {
203
+ r = e.args[t + 1];
204
+ break;
205
+ }
206
+ if (!r)
207
+ return e.stderr.write("error: switch `m' requires a value\n"), 1;
208
+ try {
209
+ const s = (await n.commit({
210
+ fs: a,
211
+ dir: i,
212
+ message: r,
213
+ author: {
214
+ name: e.env.GIT_AUTHOR_NAME || e.env.USER || "user",
215
+ email: e.env.GIT_AUTHOR_EMAIL || "user@lifo.sh"
216
+ }
217
+ })).slice(0, 7);
218
+ return e.stdout.write(`[${s}] ${r}
219
+ `), 0;
220
+ } catch (t) {
221
+ return e.stderr.write(`error: ${t instanceof Error ? t.message : String(t)}
222
+ `), 1;
223
+ }
224
+ }
225
+ async function G(n, e, a) {
226
+ const i = h(e.vfs, e.cwd);
227
+ try {
228
+ const r = await n.currentBranch({ fs: a, dir: i }) || "HEAD";
229
+ e.stdout.write(`On branch ${r}
230
+ `);
231
+ const t = await n.statusMatrix({ fs: a, dir: i }), s = [], f = [], l = [];
232
+ for (const [d, u, o, c] of t)
233
+ u === 0 && o === 2 && c === 0 ? l.push(d) : u === 0 && c === 2 ? s.push(`new file: ${d}`) : u === 1 && c === 2 ? (s.push(`modified: ${d}`), o === 2 && f.push(`modified: ${d}`)) : u === 1 && o === 2 && c === 1 ? f.push(`modified: ${d}`) : u === 1 && o === 0 && c === 0 ? s.push(`deleted: ${d}`) : u === 1 && o === 0 && c === 1 ? f.push(`deleted: ${d}`) : u === 1 && c === 3 && (s.push(`modified: ${d}`), o === 2 && f.push(`modified: ${d}`));
234
+ if (s.length > 0) {
235
+ e.stdout.write(`
236
+ Changes to be committed:
237
+ `), e.stdout.write(` (use "git restore --staged <file>..." to unstage)
238
+ `);
239
+ for (const d of s)
240
+ e.stdout.write(` \x1B[32m${d}\x1B[0m
241
+ `);
242
+ }
243
+ if (f.length > 0) {
244
+ e.stdout.write(`
245
+ Changes not staged for commit:
246
+ `), e.stdout.write(` (use "git add <file>..." to update what will be committed)
247
+ `);
248
+ for (const d of f)
249
+ e.stdout.write(` \x1B[31m${d}\x1B[0m
250
+ `);
251
+ }
252
+ if (l.length > 0) {
253
+ e.stdout.write(`
254
+ Untracked files:
255
+ `), e.stdout.write(` (use "git add <file>..." to include in what will be committed)
256
+ `);
257
+ for (const d of l)
258
+ e.stdout.write(` \x1B[31m${d}\x1B[0m
259
+ `);
260
+ }
261
+ return s.length === 0 && f.length === 0 && l.length === 0 && e.stdout.write(`nothing to commit, working tree clean
262
+ `), 0;
263
+ } catch (r) {
264
+ return e.stderr.write(`fatal: ${r instanceof Error ? r.message : String(r)}
265
+ `), 128;
266
+ }
267
+ }
268
+ async function U(n, e, a) {
269
+ const i = h(e.vfs, e.cwd);
270
+ let r = 10, t = !1;
271
+ for (let s = 0; s < e.args.length; s++)
272
+ e.args[s] === "--oneline" ? t = !0 : e.args[s] === "-n" && e.args[s + 1] ? (r = parseInt(e.args[s + 1], 10), s++) : e.args[s].startsWith("-") && !isNaN(parseInt(e.args[s].slice(1), 10)) && (r = parseInt(e.args[s].slice(1), 10));
273
+ try {
274
+ const s = await n.log({ fs: a, dir: i, depth: r });
275
+ for (const f of s) {
276
+ const { oid: l, commit: d } = f, u = l.slice(0, 7);
277
+ if (t)
278
+ e.stdout.write(`\x1B[33m${u}\x1B[0m ${d.message.split(`
279
+ `)[0]}
280
+ `);
281
+ else {
282
+ e.stdout.write(`\x1B[33mcommit ${l}\x1B[0m
283
+ `), e.stdout.write(`Author: ${d.author.name} <${d.author.email}>
284
+ `);
285
+ const o = new Date(d.author.timestamp * 1e3);
286
+ e.stdout.write(`Date: ${o.toUTCString()}
287
+ `), e.stdout.write(`
288
+ ${d.message.trim()}
289
+
290
+ `);
291
+ }
292
+ }
293
+ return 0;
294
+ } catch (s) {
295
+ return e.stderr.write(`fatal: ${s instanceof Error ? s.message : String(s)}
296
+ `), 128;
297
+ }
298
+ }
299
+ async function N(n, e, a) {
300
+ const i = h(e.vfs, e.cwd), r = e.args.includes("-d") || e.args.includes("-D"), t = e.args.filter((s) => !s.startsWith("-"));
301
+ if (r && t.length > 0)
302
+ try {
303
+ return await n.deleteBranch({ fs: a, dir: i, ref: t[0] }), e.stdout.write(`Deleted branch ${t[0]}
304
+ `), 0;
305
+ } catch (s) {
306
+ return e.stderr.write(`error: ${s instanceof Error ? s.message : String(s)}
307
+ `), 1;
308
+ }
309
+ if (t.length > 0)
310
+ try {
311
+ return await n.branch({ fs: a, dir: i, ref: t[0] }), 0;
312
+ } catch (s) {
313
+ return e.stderr.write(`fatal: ${s instanceof Error ? s.message : String(s)}
314
+ `), 128;
315
+ }
316
+ try {
317
+ const s = await n.listBranches({ fs: a, dir: i }), f = await n.currentBranch({ fs: a, dir: i });
318
+ for (const l of s)
319
+ l === f ? e.stdout.write(`* \x1B[32m${l}\x1B[0m
320
+ `) : e.stdout.write(` ${l}
321
+ `);
322
+ return 0;
323
+ } catch (s) {
324
+ return e.stderr.write(`fatal: ${s instanceof Error ? s.message : String(s)}
325
+ `), 128;
326
+ }
327
+ }
328
+ async function O(n, e, a) {
329
+ const i = h(e.vfs, e.cwd), r = e.args.includes("-b"), t = e.args.filter((s) => !s.startsWith("-"))[0];
330
+ if (!t)
331
+ return e.stderr.write(`error: you must specify a branch or commit
332
+ `), 1;
333
+ try {
334
+ return r && await n.branch({ fs: a, dir: i, ref: t }), await n.checkout({ fs: a, dir: i, ref: t }), e.stdout.write(`Switched to branch '${t}'
335
+ `), 0;
336
+ } catch (s) {
337
+ return e.stderr.write(`error: ${s instanceof Error ? s.message : String(s)}
338
+ `), 1;
339
+ }
340
+ }
341
+ async function F(n, e, a) {
342
+ const i = h(e.vfs, e.cwd), r = e.args.includes("--staged") || e.args.includes("--cached");
343
+ try {
344
+ const t = await n.statusMatrix({ fs: a, dir: i });
345
+ for (const [s, f, l, d] of t)
346
+ if (r) {
347
+ if (f === 0 && d === 2 || f === 1 && d === 2 || f === 1 && l === 0 && d === 0)
348
+ if (e.stdout.write(`diff --git a/${s} b/${s}
349
+ `), f === 0 && d === 2) {
350
+ e.stdout.write(`new file
351
+ `);
352
+ const u = e.vfs.readFileString(g(i, s));
353
+ for (const o of u.split(`
354
+ `))
355
+ e.stdout.write(`\x1B[32m+${o}\x1B[0m
356
+ `);
357
+ } else l === 0 && d === 0 ? e.stdout.write(`deleted file
358
+ `) : e.stdout.write(`modified file
359
+ `);
360
+ } else
361
+ l === 2 && (d === 1 || d === 3) && (e.stdout.write(`diff --git a/${s} b/${s}
362
+ `), e.stdout.write(`modified file
363
+ `));
364
+ return 0;
365
+ } catch (t) {
366
+ return e.stderr.write(`fatal: ${t instanceof Error ? t.message : String(t)}
367
+ `), 128;
368
+ }
369
+ }
370
+ async function M(n, e, a) {
371
+ const i = h(e.vfs, e.cwd), r = e.args[0];
372
+ if (r === "add" && e.args.length >= 3) {
373
+ const t = e.args[1], s = e.args[2];
374
+ try {
375
+ return await n.addRemote({ fs: a, dir: i, remote: t, url: s }), 0;
376
+ } catch (f) {
377
+ return e.stderr.write(`fatal: ${f instanceof Error ? f.message : String(f)}
378
+ `), 128;
379
+ }
380
+ }
381
+ if (r === "remove" && e.args.length >= 2) {
382
+ const t = e.args[1];
383
+ try {
384
+ return await n.deleteRemote({ fs: a, dir: i, remote: t }), 0;
385
+ } catch (s) {
386
+ return e.stderr.write(`fatal: ${s instanceof Error ? s.message : String(s)}
387
+ `), 128;
388
+ }
389
+ }
390
+ try {
391
+ const t = e.args.includes("-v") || e.args.includes("--verbose"), s = await n.listRemotes({ fs: a, dir: i });
392
+ for (const { remote: f, url: l } of s)
393
+ t ? (e.stdout.write(`${f} ${l} (fetch)
394
+ `), e.stdout.write(`${f} ${l} (push)
395
+ `)) : e.stdout.write(`${f}
396
+ `);
397
+ return 0;
398
+ } catch (t) {
399
+ return e.stderr.write(`fatal: ${t instanceof Error ? t.message : String(t)}
400
+ `), 128;
401
+ }
402
+ }
403
+ async function C(n, e, a) {
404
+ const i = h(e.vfs, e.cwd);
405
+ let r = "origin", t, s = !1, f = !1;
406
+ const l = [];
407
+ for (let u = 0; u < e.args.length; u++) {
408
+ const o = e.args[u];
409
+ o === "-f" || o === "--force" ? s = !0 : o === "-u" || o === "--set-upstream" ? f = !0 : o.startsWith("-") || l.push(o);
410
+ }
411
+ if (l.length >= 1 && (r = l[0]), l.length >= 2 && (t = l[1]), !t) {
412
+ const u = await n.currentBranch({ fs: a, dir: i });
413
+ if (!u)
414
+ return e.stderr.write(`fatal: You are not currently on a branch.
415
+ `), 128;
416
+ t = u;
417
+ }
418
+ const d = $(e.env);
419
+ try {
420
+ const u = await n.push({
421
+ fs: a,
422
+ http: m(),
423
+ dir: i,
424
+ remote: r,
425
+ ref: t,
426
+ remoteRef: t,
427
+ force: s,
428
+ onAuth: d,
429
+ onMessage(o) {
430
+ e.stderr.write(`remote: ${o}
431
+ `);
432
+ }
433
+ });
434
+ if (u.ok) {
435
+ if (e.stdout.write(`To ${await b(n, a, i, r)}
436
+ `), e.stdout.write(` ${t} -> ${t}
437
+ `), f) {
438
+ const o = `${i}/.git/config`;
439
+ try {
440
+ const c = e.vfs.readFileString(o), w = `[branch "${t}"]
441
+ remote = ${r}
442
+ merge = refs/heads/${t}
443
+ `;
444
+ c.includes(`[branch "${t}"]`) || e.vfs.writeFile(o, c + `
445
+ ` + w);
446
+ } catch {
447
+ }
448
+ }
449
+ } else
450
+ return e.stderr.write(`error: failed to push some refs
451
+ `), u.error && e.stderr.write(`error: ${u.error}
452
+ `), 1;
453
+ return 0;
454
+ } catch (u) {
455
+ const o = u instanceof Error ? u.message : String(u);
456
+ return o.includes("401") || o.includes("403") || o.includes("Authentication") ? (e.stderr.write(`fatal: Authentication failed for '${r}'
457
+ `), e.stderr.write(`hint: Set GIT_TOKEN or GIT_USERNAME/GIT_PASSWORD env vars
458
+ `)) : e.stderr.write(`fatal: ${o}
459
+ `), 128;
460
+ }
461
+ }
462
+ async function D(n, e, a) {
463
+ const i = h(e.vfs, e.cwd);
464
+ let r, t;
465
+ const s = [];
466
+ for (const u of e.args)
467
+ u.startsWith("-") || s.push(u);
468
+ s.length >= 1 && (r = s[0]), s.length >= 2 && (t = s[1]);
469
+ const f = $(e.env), l = await n.currentBranch({ fs: a, dir: i });
470
+ if (!l)
471
+ return e.stderr.write(`fatal: You are not currently on a branch.
472
+ `), 128;
473
+ const d = r || "origin";
474
+ e.stdout.write(`Pulling from ${d}...
475
+ `);
476
+ try {
477
+ return await n.pull({
478
+ fs: a,
479
+ http: m(),
480
+ dir: i,
481
+ remote: d,
482
+ ref: t || l,
483
+ singleBranch: !0,
484
+ fastForward: !0,
485
+ fastForwardOnly: !1,
486
+ onAuth: f,
487
+ onMessage(u) {
488
+ e.stderr.write(`remote: ${u}
489
+ `);
490
+ },
491
+ author: {
492
+ name: e.env.GIT_AUTHOR_NAME || e.env.USER || "user",
493
+ email: e.env.GIT_AUTHOR_EMAIL || "user@lifo.sh"
494
+ }
495
+ }), e.stdout.write(`Already up to date.
496
+ `), 0;
497
+ } catch (u) {
498
+ const o = u instanceof Error ? u.message : String(u);
499
+ return o.includes("401") || o.includes("403") || o.includes("Authentication") ? (e.stderr.write(`fatal: Authentication failed for '${r || "origin"}'
500
+ `), e.stderr.write(`hint: Set GIT_TOKEN or GIT_USERNAME/GIT_PASSWORD env vars
501
+ `)) : e.stderr.write(`fatal: ${o}
502
+ `), 128;
503
+ }
504
+ }
505
+ async function P(n, e, a) {
506
+ const i = h(e.vfs, e.cwd);
507
+ let r, t, s, f = !1;
508
+ const l = [];
509
+ for (let o = 0; o < e.args.length; o++) {
510
+ const c = e.args[o];
511
+ c === "--tags" ? f = !0 : c === "--depth" && e.args[o + 1] ? (s = parseInt(e.args[o + 1], 10), o++) : c.startsWith("-") || l.push(c);
512
+ }
513
+ l.length >= 1 && (r = l[0]), l.length >= 2 && (t = l[1]);
514
+ const d = $(e.env), u = r || "origin";
515
+ e.stdout.write(`Fetching from ${u}...
516
+ `);
517
+ try {
518
+ const o = await n.fetch({
519
+ fs: a,
520
+ http: m(),
521
+ dir: i,
522
+ remote: u,
523
+ ref: t,
524
+ singleBranch: !t,
525
+ tags: f,
526
+ depth: s ?? void 0,
527
+ onAuth: d,
528
+ onMessage(c) {
529
+ e.stderr.write(`remote: ${c}
530
+ `);
531
+ }
532
+ });
533
+ return o.fetchHead && (e.stdout.write(`From ${await b(n, a, i, u)}
534
+ `), o.fetchHeadDescription && e.stdout.write(` * ${o.fetchHeadDescription}
535
+ `)), 0;
536
+ } catch (o) {
537
+ const c = o instanceof Error ? o.message : String(o);
538
+ return c.includes("401") || c.includes("403") || c.includes("Authentication") ? (e.stderr.write(`fatal: Authentication failed for '${u}'
539
+ `), e.stderr.write(`hint: Set GIT_TOKEN or GIT_USERNAME/GIT_PASSWORD env vars
540
+ `)) : e.stderr.write(`fatal: ${c}
541
+ `), 128;
542
+ }
543
+ }
544
+ function $(n) {
545
+ return () => {
546
+ if (n.GIT_TOKEN)
547
+ return { username: n.GIT_TOKEN };
548
+ if (n.GIT_USERNAME)
549
+ return { username: n.GIT_USERNAME, password: n.GIT_PASSWORD || "" };
550
+ };
551
+ }
552
+ async function b(n, e, a, i) {
553
+ try {
554
+ const t = (await n.listRemotes({ fs: e, dir: a })).find((s) => s.remote === i);
555
+ return (t == null ? void 0 : t.url) || i;
556
+ } catch {
557
+ return i;
558
+ }
559
+ }
560
+ const H = async (n) => {
561
+ const e = n.args[0];
562
+ if (!e || e === "--help" || e === "-h")
563
+ return n.stdout.write(v), e ? 0 : 1;
564
+ const a = await A(), i = {
565
+ ...n,
566
+ args: n.args.slice(1)
567
+ }, r = T(n.vfs);
568
+ if (e === "init") return B(a, i, r);
569
+ if (e === "clone") return _(a, i, r);
570
+ if (!h(n.vfs, n.cwd))
571
+ return n.stderr.write(`fatal: not a git repository (or any of the parent directories): .git
572
+ `), 128;
573
+ switch (e) {
574
+ case "add":
575
+ return I(a, i, r);
576
+ case "commit":
577
+ return k(a, i, r);
578
+ case "status":
579
+ return G(a, i, r);
580
+ case "log":
581
+ return U(a, i, r);
582
+ case "branch":
583
+ return N(a, i, r);
584
+ case "checkout":
585
+ return O(a, i, r);
586
+ case "diff":
587
+ return F(a, i, r);
588
+ case "remote":
589
+ return M(a, i, r);
590
+ case "push":
591
+ return C(a, i, r);
592
+ case "pull":
593
+ return D(a, i, r);
594
+ case "fetch":
595
+ return P(a, i, r);
596
+ default:
597
+ return n.stderr.write(`git: '${e}' is not a git command. See 'git --help'.
598
+ `), 1;
599
+ }
600
+ };
601
+ export {
602
+ H as default
603
+ };