reslop 0.1.9 → 0.2.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +3 -1
  3. package/bin/reslop.js +2 -2
  4. package/lib/ansi.js +148 -5
  5. package/lib/api.js +4 -2
  6. package/lib/capabilities.js +13 -14
  7. package/lib/cli.js +38 -49
  8. package/lib/clipboard.js +1 -1
  9. package/lib/{deps/changes.js → deps-diff.js} +309 -19
  10. package/lib/deps.js +498 -29
  11. package/lib/detect.js +1 -7
  12. package/lib/diff/align.js +7 -10
  13. package/lib/diff/diff.js +53 -0
  14. package/lib/diff/display.js +5 -4
  15. package/lib/diff/inline.js +26 -21
  16. package/lib/diff/items.js +6 -4
  17. package/lib/diff/patch.js +1 -3
  18. package/lib/diff/unit.js +392 -0
  19. package/lib/files.js +5 -8
  20. package/lib/{git/branches.js → git-branches.js} +191 -11
  21. package/lib/{git/dependencies.js → git-deps.js} +111 -38
  22. package/lib/git-reword-todo.js +20 -0
  23. package/lib/git.js +606 -68
  24. package/lib/github.js +28 -197
  25. package/lib/gitlab.js +24 -195
  26. package/lib/highlight/bash.js +1 -3
  27. package/lib/highlight/css.js +1 -3
  28. package/lib/highlight/js.js +11 -14
  29. package/lib/highlight.js +6 -9
  30. package/lib/keys.js +14 -8
  31. package/lib/manifest.js +330 -0
  32. package/lib/remote.js +374 -0
  33. package/lib/render/branches.js +18 -100
  34. package/lib/render/chrome.js +71 -14
  35. package/lib/render/commits.js +69 -60
  36. package/lib/render/diff.js +20 -20
  37. package/lib/render/files.js +6 -34
  38. package/lib/render/frame.js +36 -13
  39. package/lib/render/notes.js +26 -8
  40. package/lib/render/primitives.js +99 -11
  41. package/lib/{render.js → render/render.js} +8 -8
  42. package/lib/render/unit.js +41 -0
  43. package/lib/review-merge.js +270 -0
  44. package/lib/review.js +782 -14
  45. package/lib/select.js +5 -10
  46. package/lib/session/accessors.js +9 -1
  47. package/lib/session/actions.js +61 -18
  48. package/lib/session/branches.js +116 -128
  49. package/lib/session/change-actions.js +202 -123
  50. package/lib/session/commit.js +201 -115
  51. package/lib/session/compose.js +181 -15
  52. package/lib/session/dispatch.js +110 -60
  53. package/lib/session/files-pane.js +156 -148
  54. package/lib/session/items.js +22 -30
  55. package/lib/session/lifecycle.js +151 -54
  56. package/lib/session/load.js +19 -33
  57. package/lib/session/navigation.js +12 -1
  58. package/lib/session/ops.js +28 -41
  59. package/lib/session/pointer.js +57 -57
  60. package/lib/session/review.js +23 -37
  61. package/lib/session/terminal.js +6 -12
  62. package/lib/session/todos.js +37 -13
  63. package/lib/session/unit.js +208 -0
  64. package/lib/session/update.js +33 -46
  65. package/lib/session/view.js +78 -9
  66. package/lib/session/watch.js +128 -24
  67. package/lib/session.js +22 -246
  68. package/lib/source.js +3 -3
  69. package/lib/update.js +40 -75
  70. package/lib/{git/proc.js → utilities.js} +75 -11
  71. package/lib/wrap.js +1 -3
  72. package/package.json +2 -2
  73. package/lib/deps/items.js +0 -134
  74. package/lib/deps/manifest.js +0 -152
  75. package/lib/deps/merge.js +0 -120
  76. package/lib/deps/proposals.js +0 -164
  77. package/lib/deps/reports.js +0 -180
  78. package/lib/deps/rows.js +0 -176
  79. package/lib/deps/scan.js +0 -138
  80. package/lib/deps/usage.js +0 -68
  81. package/lib/deps/versions.js +0 -119
  82. package/lib/diff.js +0 -33
  83. package/lib/git/changes.js +0 -164
  84. package/lib/git/read.js +0 -253
  85. package/lib/git/run.js +0 -100
  86. package/lib/npm/commands.js +0 -100
  87. package/lib/remote/changes.js +0 -37
  88. package/lib/remote/headers.js +0 -36
  89. package/lib/remote/http.js +0 -122
  90. package/lib/remote/notes.js +0 -94
  91. package/lib/review/format.js +0 -434
  92. package/lib/review/storage.js +0 -150
  93. package/lib/review/store.js +0 -178
  94. package/lib/review/templates.js +0 -49
  95. package/lib/session/origins.js +0 -7
  96. package/lib/sys.js +0 -84
package/lib/git.js CHANGED
@@ -1,57 +1,582 @@
1
1
  'use strict';
2
2
 
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+
6
+ const proc = require('./utilities.js');
7
+ const { runProc, runProcSync, isAbort } = proc;
3
8
  const { capabilitiesFor, attachCapabilities } = require('./capabilities.js');
4
- const read = require('./git/read.js');
5
- const changes = require('./git/changes.js');
6
- const branches = require('./git/branches.js');
7
- const dependencies = require('./git/dependencies.js');
9
+ const diff = require('./diff/diff.js');
10
+ const { parseDiff, synthesizeNewFile, itemsFromFiles } = diff;
11
+ const { itemPath, REVIEW_DIR } = require('./files.js');
12
+ const { replaceBlockAdds } = require('./diff/edit.js');
13
+
14
+ const oneLine = (text, fallback = 'git failed') => proc.oneLine(text, fallback);
15
+
16
+ const GIT_CONFIG = [
17
+ '-c',
18
+ 'core.quotepath=false',
19
+ '-c',
20
+ 'i18n.logOutputEncoding=utf-8',
21
+ ];
22
+ const DIFF_OPTS = ['--no-color', '--no-ext-diff', '--no-renames', '-U3'];
23
+ const GIT_ENCODING = proc.DEFAULT_ENCODING;
24
+ const GIT_MAX_BUFFER = proc.DEFAULT_MAX_BUFFER;
25
+
26
+ const gitProcOptions = (cwd, extra = {}) => ({
27
+ cwd,
28
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: '0', ...extra.env },
29
+ encoding: GIT_ENCODING,
30
+ maxBuffer: GIT_MAX_BUFFER,
31
+ input: extra.input,
32
+ signal: extra.signal,
33
+ });
34
+
35
+ const gitResult = (result) => {
36
+ if (!result.error) return result;
37
+ if (isAbort(result.error)) throw result.error;
38
+ if (result.error.code === 'ENOENT') throw new Error('git not found');
39
+ throw result.error;
40
+ };
41
+
42
+ const requireOk = (result, fallback = 'git failed') => {
43
+ if (result.status === 0) return result;
44
+ const msg = result.stderr || result.stdout || fallback;
45
+ throw new Error(oneLine(msg, fallback));
46
+ };
47
+
48
+ const runGit = (args, cwd, input, extra = {}) => {
49
+ const options = gitProcOptions(cwd, { input, env: extra.env });
50
+ return gitResult(runProcSync('git', args, options));
51
+ };
52
+
53
+ const runGitAsync = (args, cwd, extra = {}) => {
54
+ const options = gitProcOptions(cwd, extra);
55
+ return runProc('git', args, options).then(gitResult);
56
+ };
57
+
58
+ const pathArgsOf = (paths) => (paths.length ? ['--', ...paths] : []);
59
+
60
+ const cachedDiffArgs = (pathArgs) => [
61
+ ...GIT_CONFIG,
62
+ 'diff',
63
+ '--cached',
64
+ ...DIFF_OPTS,
65
+ ...pathArgs,
66
+ ];
67
+
68
+ const worktreeDiffArgs = (pathArgs) => [
69
+ ...GIT_CONFIG,
70
+ 'diff',
71
+ ...DIFF_OPTS,
72
+ ...pathArgs,
73
+ ];
74
+
75
+ const commitDiffArgs = (commit, parent, pathArgs) => {
76
+ if (parent.status === 0) {
77
+ const from = parent.stdout.trim();
78
+ return [...GIT_CONFIG, 'diff', ...DIFF_OPTS, from, commit, ...pathArgs];
79
+ }
80
+ return [
81
+ ...GIT_CONFIG,
82
+ 'diff-tree',
83
+ '--no-commit-id',
84
+ '--root',
85
+ '-p',
86
+ ...DIFF_OPTS,
87
+ commit,
88
+ ...pathArgs,
89
+ ];
90
+ };
91
+
92
+ const BINARY_SIZE = 1000000;
93
+
94
+ const isReviewFile = (rel) => {
95
+ if (!rel) return false;
96
+ const first = rel.split(/[/\\]/)[0];
97
+ return first === REVIEW_DIR;
98
+ };
99
+
100
+ const dropReviewItems = (items) => {
101
+ const kept = [];
102
+ for (const item of items) {
103
+ if (isReviewFile(itemPath(item))) continue;
104
+ kept.push(item);
105
+ }
106
+ return kept;
107
+ };
108
+
109
+ const isBinaryBuffer = (buf) => {
110
+ if (buf.length > BINARY_SIZE) return true;
111
+ return buf.includes(0);
112
+ };
113
+
114
+ const namesFromLs = (stdout) => {
115
+ if (!stdout) return [];
116
+ return stdout.split('\0').filter(Boolean);
117
+ };
118
+
119
+ const untrackedLsArgs = (paths) => {
120
+ const args = ['ls-files', '-o', '--exclude-standard', '-z'];
121
+ if (paths.length) args.push('--', ...paths);
122
+ return args;
123
+ };
124
+
125
+ const listUntracked = (top, paths) => {
126
+ const result = requireOk(runGit(untrackedLsArgs(paths), top));
127
+ return namesFromLs(result.stdout);
128
+ };
129
+
130
+ const filterListed = (names) => {
131
+ const out = [];
132
+ for (const rel of names) {
133
+ if (!rel || isReviewFile(rel)) continue;
134
+ out.push(rel);
135
+ }
136
+ return out;
137
+ };
138
+
139
+ const listTreeArgs = (rev, paths) => {
140
+ const args = ['ls-tree', '-r', '--name-only', '-z', rev];
141
+ if (paths.length) args.push('--', ...paths);
142
+ return args;
143
+ };
144
+
145
+ const listWorktreeArgs = (paths) => {
146
+ const args = ['ls-files', '-co', '--exclude-standard', '-z'];
147
+ if (paths.length) args.push('--', ...paths);
148
+ return args;
149
+ };
150
+
151
+ const listScopeFiles = (top, paths = [], options = {}) => {
152
+ const rev = options.commit;
153
+ const args = rev ? listTreeArgs(rev, paths) : listWorktreeArgs(paths);
154
+ const result = requireOk(runGit(args, top), 'ls-files failed');
155
+ const names = filterListed(namesFromLs(result.stdout));
156
+ names.sort((left, right) => left.localeCompare(right, 'en'));
157
+ return names;
158
+ };
159
+
160
+ const binaryNewFile = (rel) => ({
161
+ oldPath: rel,
162
+ newPath: rel,
163
+ isNew: true,
164
+ isDeleted: false,
165
+ isBinary: true,
166
+ preamble: [`diff --git a/${rel} b/${rel}`, 'new file mode 100644'],
167
+ hunks: [],
168
+ });
169
+
170
+ const untrackedItemsFrom = (top, names) => {
171
+ const files = [];
172
+ for (const rel of names) {
173
+ if (isReviewFile(rel)) continue;
174
+ const full = path.join(top, rel);
175
+ let buf;
176
+ try {
177
+ buf = fs.readFileSync(full);
178
+ } catch (error) {
179
+ if (error.code === 'ENOENT') continue;
180
+ throw error;
181
+ }
182
+ if (isBinaryBuffer(buf)) {
183
+ files.push(binaryNewFile(rel));
184
+ continue;
185
+ }
186
+ files.push(synthesizeNewFile(rel, buf.toString('utf8')));
187
+ }
188
+ return itemsFromFiles(files, 'untracked');
189
+ };
190
+
191
+ const mergeItems = (groups) => {
192
+ const byPath = new Map();
193
+ for (const group of groups) {
194
+ for (const item of group) {
195
+ const rel = itemPath(item);
196
+ const list = byPath.get(rel);
197
+ if (list) {
198
+ list.push(item);
199
+ continue;
200
+ }
201
+ byPath.set(rel, [item]);
202
+ }
203
+ }
204
+ let size = 0;
205
+ for (const list of byPath.values()) size += list.length;
206
+ const items = new Array(size);
207
+ let i = 0;
208
+ for (const list of byPath.values()) {
209
+ for (const item of list) items[i++] = item;
210
+ }
211
+ return items;
212
+ };
213
+
214
+ const gitText = (top, spec) => {
215
+ const result = runGit(['show', spec], top);
216
+ if (result.status !== 0) return '';
217
+ return result.stdout ?? '';
218
+ };
219
+
220
+ const worktreeText = (top, rel) => {
221
+ try {
222
+ return fs.readFileSync(path.join(top, rel), 'utf8');
223
+ } catch {
224
+ return '';
225
+ }
226
+ };
227
+
228
+ const fileText = (top, rel, rev) => {
229
+ if (!rel) return '';
230
+ if (rev) return gitText(top, `${rev}:${rel}`);
231
+ return worktreeText(top, rel);
232
+ };
233
+
234
+ const readDepSides = (top, rev, origin, rel) => {
235
+ if (origin === 'untracked') {
236
+ const newText = worktreeText(top, rel);
237
+ return { oldText: '', newText };
238
+ }
239
+ if (origin === 'staged') {
240
+ const oldText = gitText(top, `HEAD:${rel}`);
241
+ const newText = gitText(top, `:${rel}`);
242
+ return { oldText, newText };
243
+ }
244
+ if (origin === 'unstaged') {
245
+ const indexed = gitText(top, `:${rel}`);
246
+ const oldText = indexed || gitText(top, `HEAD:${rel}`);
247
+ const newText = worktreeText(top, rel);
248
+ return { oldText, newText };
249
+ }
250
+ if (origin === 'commit' && rev) {
251
+ const oldText = gitText(top, `${rev}^:${rel}`);
252
+ const newText = gitText(top, `${rev}:${rel}`);
253
+ return { oldText, newText };
254
+ }
255
+ return { oldText: '', newText: '' };
256
+ };
257
+
258
+ const toplevel = (cwd) => {
259
+ const result = runGit(['rev-parse', '--show-toplevel'], cwd);
260
+ if (result.status !== 0) throw new Error('not a git repository');
261
+ return result.stdout.trim();
262
+ };
263
+
264
+ const resolveRev = (cwd, spec) => {
265
+ if (!spec) return null;
266
+ const top = toplevel(cwd);
267
+ const args = ['rev-parse', '--verify', `${spec}^{commit}`];
268
+ const result = runGit(args, top);
269
+ if (result.status !== 0) return null;
270
+ return result.stdout.trim();
271
+ };
272
+
273
+ const shortRev = (top, commit) => {
274
+ const result = runGit(['rev-parse', '--short', commit], top);
275
+ if (result.status !== 0) return commit.slice(0, 7);
276
+ return result.stdout.trim();
277
+ };
278
+
279
+ const currentBranch = (top) => {
280
+ const args = ['rev-parse', '--abbrev-ref', 'HEAD'];
281
+ const result = runGit(args, top);
282
+ if (result.status !== 0) return '';
283
+ const name = result.stdout.trim();
284
+ if (!name || name === 'HEAD') return '';
285
+ return name;
286
+ };
287
+
288
+ const snapshotWorktree = (top, stagedOut, unstagedOut, names) => {
289
+ const stagedDiff = parseDiff(stagedOut);
290
+ const unstagedDiff = parseDiff(unstagedOut);
291
+ const staged = itemsFromFiles(stagedDiff, 'staged');
292
+ const unstaged = itemsFromFiles(unstagedDiff, 'unstaged');
293
+ const untracked = untrackedItemsFrom(top, names);
294
+ const combined = mergeItems([staged, unstaged, untracked]);
295
+ const parsed = dropReviewItems(combined);
296
+ const branch = currentBranch(top);
297
+ return { top, parsed, branch };
298
+ };
299
+
300
+ const snapshotCommit = (top, commit, files) => {
301
+ const commitItems = itemsFromFiles(files, 'commit');
302
+ const parsed = dropReviewItems(commitItems);
303
+ const revShort = shortRev(top, commit);
304
+ const branch = currentBranch(top);
305
+ return { top, parsed, rev: commit, revShort, branch };
306
+ };
307
+
308
+ const loadCommit = (top, commit, extra) => {
309
+ const parent = runGit(['rev-parse', '--verify', `${commit}^`], top);
310
+ const args = commitDiffArgs(commit, parent, extra);
311
+ const result = requireOk(runGit(args, top));
312
+ return parseDiff(result.stdout);
313
+ };
314
+
315
+ const loadCommitAsync = async (top, commit, extra, signal) => {
316
+ const parent = await runGitAsync(
317
+ ['rev-parse', '--verify', `${commit}^`],
318
+ top,
319
+ { signal },
320
+ );
321
+ const args = commitDiffArgs(commit, parent, extra);
322
+ const result = requireOk(await runGitAsync(args, top, { signal }));
323
+ return parseDiff(result.stdout);
324
+ };
325
+
326
+ const readSnapshot = (cwd, paths, options) => {
327
+ const top = toplevel(cwd);
328
+ const extra = pathArgsOf(paths);
329
+ const rev = options.commit;
330
+ if (rev) return snapshotCommit(top, rev, loadCommit(top, rev, extra));
331
+ const stagedRes = requireOk(runGit(cachedDiffArgs(extra), top));
332
+ const unstagedRes = requireOk(runGit(worktreeDiffArgs(extra), top));
333
+ const names = listUntracked(top, paths);
334
+ return snapshotWorktree(top, stagedRes.stdout, unstagedRes.stdout, names);
335
+ };
336
+
337
+ const readSnapshotAsync = async (cwd, paths, options) => {
338
+ const top = toplevel(cwd);
339
+ const extra = pathArgsOf(paths);
340
+ const rev = options.commit;
341
+ const signal = options.signal;
342
+ if (rev) {
343
+ const files = await loadCommitAsync(top, rev, extra, signal);
344
+ return snapshotCommit(top, rev, files);
345
+ }
346
+ const stagedArgs = cachedDiffArgs(extra);
347
+ const unstagedArgs = worktreeDiffArgs(extra);
348
+ const lsArgs = untrackedLsArgs(paths);
349
+ const stagedP = runGitAsync(stagedArgs, top, { signal });
350
+ const unstagedP = runGitAsync(unstagedArgs, top, { signal });
351
+ const lsP = runGitAsync(lsArgs, top, { signal });
352
+ const extras = await Promise.all([stagedP, unstagedP, lsP]);
353
+ const stagedRes = extras[0];
354
+ const unstagedRes = extras[1];
355
+ const lsRes = extras[2];
356
+ requireOk(stagedRes);
357
+ requireOk(unstagedRes);
358
+ const names = namesFromLs(requireOk(lsRes).stdout);
359
+ return snapshotWorktree(top, stagedRes.stdout, unstagedRes.stdout, names);
360
+ };
361
+
362
+ const applyPatch = (cwd, patch, flags) => {
363
+ const args = ['apply', ...flags, '--whitespace=nowarn', '-'];
364
+ const result = runGit(args, cwd, patch);
365
+ requireOk(result, 'apply failed');
366
+ };
367
+
368
+ const addItem = (top, item) => {
369
+ if (item.origin === 'staged' || item.origin === 'commit') return;
370
+ if (item.origin === 'untracked' || item.file.isBinary) {
371
+ return void requireOk(runGit(['add', '--', item.file.newPath], top));
372
+ }
373
+ applyPatch(top, item.patchAdd, ['--cached']);
374
+ };
375
+
376
+ const unstageItem = (top, item) => {
377
+ if (item.origin !== 'staged') return;
378
+ const rel = itemPath(item);
379
+ if (item.file.isBinary) {
380
+ return void requireOk(runGit(['restore', '--staged', '--', rel], top));
381
+ }
382
+ applyPatch(top, item.patchAdd, ['--reverse', '--cached']);
383
+ };
384
+
385
+ const revertOnePath = (top, rel, items) => {
386
+ const origins = new Set();
387
+ let isNew = false;
388
+ for (const item of items) {
389
+ origins.add(item.origin);
390
+ if (item.file && item.file.isNew) isNew = true;
391
+ }
392
+ if (isNew) {
393
+ if (origins.has('staged')) {
394
+ return void requireOk(runGit(['rm', '-f', '--', rel], top));
395
+ }
396
+ return void fs.unlinkSync(path.join(top, rel));
397
+ }
398
+ if (origins.has('untracked') && origins.size === 1) {
399
+ return void fs.unlinkSync(path.join(top, rel));
400
+ }
401
+ const args = ['restore', '-s', 'HEAD', '--worktree', '--staged', '--', rel];
402
+ requireOk(runGit(args, top));
403
+ };
404
+
405
+ const revertItem = (top, item) => {
406
+ if (item.origin === 'commit') return;
407
+ const rel = itemPath(item);
408
+ if (item.origin === 'untracked') {
409
+ return void fs.unlinkSync(path.join(top, rel));
410
+ }
411
+ if (item.file.isBinary) {
412
+ const args = ['restore', '-s', 'HEAD', '--worktree'];
413
+ if (item.origin === 'staged') args.push('--staged');
414
+ args.push('--', rel);
415
+ return void requireOk(runGit(args, top));
416
+ }
417
+ if (item.origin === 'unstaged') {
418
+ return void applyPatch(top, item.patchRevert, ['--reverse']);
419
+ }
420
+ applyPatch(top, item.patchRevert, ['--reverse', '--cached']);
421
+ try {
422
+ applyPatch(top, item.patchRevert, ['--reverse']);
423
+ } catch (error) {
424
+ if (!error.message.includes('does not apply')) throw error;
425
+ }
426
+ };
427
+
428
+ const revertFile = (top, rel, items) => {
429
+ const group = [];
430
+ for (const item of items) {
431
+ if (itemPath(item) === rel) group.push(item);
432
+ }
433
+ const targets = group.length ? group : items;
434
+ revertOnePath(top, rel, targets);
435
+ };
436
+
437
+ const indexText = (top, rel) => {
438
+ const result = runGit(['show', `:${rel}`], top);
439
+ requireOk(result, 'show failed');
440
+ return result.stdout ?? '';
441
+ };
442
+
443
+ const indexMode = (top, rel) => {
444
+ const result = runGit(['ls-files', '--stage', '--', rel], top);
445
+ if (result.status !== 0) return '100644';
446
+ const line = (result.stdout ?? '').trim();
447
+ if (!line) return '100644';
448
+ const mode = line.split(' ')[0];
449
+ return mode || '100644';
450
+ };
451
+
452
+ const writeIndex = (top, rel, text) => {
453
+ const hashed = runGit(['hash-object', '-w', '--stdin'], top, text);
454
+ requireOk(hashed, 'hash-object failed');
455
+ const sha = (hashed.stdout ?? '').trim();
456
+ const mode = indexMode(top, rel);
457
+ const args = ['update-index', '--cacheinfo', mode, sha, rel];
458
+ requireOk(runGit(args, top), 'update-index failed');
459
+ };
460
+
461
+ const writeWorktree = (abs, text) => {
462
+ fs.writeFileSync(abs, text);
463
+ };
464
+
465
+ const editStaged = (top, rel, abs, hunk, blockId, text) => {
466
+ const source = indexText(top, rel);
467
+ const next = replaceBlockAdds(source, hunk, blockId, text);
468
+ writeIndex(top, rel, next);
469
+ let work = null;
470
+ try {
471
+ work = fs.readFileSync(abs, 'utf8');
472
+ } catch (error) {
473
+ if (error.code !== 'ENOENT') throw error;
474
+ }
475
+ if (work === null) {
476
+ return void writeWorktree(abs, next);
477
+ }
478
+ if (work === source) writeWorktree(abs, next);
479
+ };
480
+
481
+ const editWorktree = (abs, hunk, blockId, text) => {
482
+ const source = fs.readFileSync(abs, 'utf8');
483
+ const next = replaceBlockAdds(source, hunk, blockId, text);
484
+ if (next === source) return;
485
+ writeWorktree(abs, next);
486
+ };
487
+
488
+ const editItem = (top, item, text) => {
489
+ if (item.origin === 'commit' || item.origin === 'pr') return;
490
+ const rel = itemPath(item);
491
+ if (!rel || !item.hunk) return;
492
+ const abs = path.join(top, rel);
493
+ if (item.origin === 'staged') {
494
+ return void editStaged(top, rel, abs, item.hunk, item.blockId, text);
495
+ }
496
+ editWorktree(abs, item.hunk, item.blockId, text);
497
+ };
498
+
499
+ const writeFile = (top, rel, text) => {
500
+ if (!rel) return;
501
+ const abs = path.join(top, rel);
502
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
503
+ writeWorktree(abs, text);
504
+ };
505
+
506
+ const stagePath = (top, rel) => {
507
+ if (!rel) return;
508
+ requireOk(runGit(['add', '--', rel], top));
509
+ };
510
+
511
+ module.exports = {
512
+ oneLine,
513
+ requireOk,
514
+ runGit,
515
+ runGitAsync,
516
+ gitText,
517
+ worktreeText,
518
+ readDepSides,
519
+ revertOnePath,
520
+ toplevel,
521
+ resolveRev,
522
+ currentBranch,
523
+ fileText,
524
+ listScopeFiles,
525
+ readSnapshot,
526
+ readSnapshotAsync,
527
+ editItem,
528
+ writeFile,
529
+ stagePath,
530
+ };
531
+
532
+ const branches = require('./git-branches.js');
533
+ const gitDeps = require('./git-deps.js');
8
534
 
9
535
  const load = (cwd, paths = [], options = {}) => {
10
- const snapshot = read.readSnapshot(cwd, paths, options);
11
- return dependencies.finishLoad(snapshot, { ...options, paths });
536
+ const snapshot = readSnapshot(cwd, paths, options);
537
+ return gitDeps.finishLoad(snapshot, { ...options, paths });
12
538
  };
13
539
 
14
540
  const loadAsync = async (cwd, paths = [], options = {}) => {
15
- const snapshot = await read.readSnapshotAsync(cwd, paths, options);
16
- return dependencies.finishLoad(snapshot, {
541
+ const snapshot = await readSnapshotAsync(cwd, paths, options);
542
+ return gitDeps.finishLoad(snapshot, {
17
543
  ...options,
18
544
  paths,
19
545
  deferExtras: options.deferExtras ?? true,
20
546
  });
21
547
  };
22
548
 
23
- const addItem = (top, item) => {
24
- if (dependencies.handles(item)) return dependencies.addItem(top, item);
25
- return changes.addItem(top, item);
549
+ const addGitItem = (top, item) => {
550
+ if (gitDeps.handles(item)) return gitDeps.addItem(top, item);
551
+ return addItem(top, item);
26
552
  };
27
553
 
28
- const addItemAsync = async (top, item) => {
29
- if (dependencies.handles(item)) {
30
- await dependencies.addItemAsync(top, item);
554
+ const addGitItemAsync = async (top, item) => {
555
+ if (gitDeps.handles(item)) {
556
+ await gitDeps.addItemAsync(top, item);
31
557
  return;
32
558
  }
33
- addItem(top, item);
559
+ addGitItem(top, item);
34
560
  };
35
561
 
36
- const unstageItem = (top, item) => {
37
- if (dependencies.handles(item)) return dependencies.unstageItem(top, item);
38
- return changes.unstageItem(top, item);
562
+ const unstageGitItem = (top, item) => {
563
+ if (gitDeps.handles(item)) return gitDeps.unstageItem(top, item);
564
+ return unstageItem(top, item);
39
565
  };
40
566
 
41
- const revertItem = (top, item) => {
567
+ const revertGitItem = (top, item) => {
42
568
  if (item.origin === 'commit') return;
43
- if (dependencies.handles(item)) {
44
- dependencies.revertDepItem(top, item);
45
- return;
569
+ if (gitDeps.handles(item)) {
570
+ return void gitDeps.revertDepItem(top, item);
46
571
  }
47
- changes.revertItem(top, item);
572
+ revertItem(top, item);
48
573
  };
49
574
 
50
- const revertFile = (top, rel, items) => {
51
- if (dependencies.relatedFiles(items).length) {
52
- return dependencies.revertFile(top, rel, items);
575
+ const revertGitFile = (top, rel, items) => {
576
+ if (gitDeps.relatedFiles(items).length) {
577
+ return gitDeps.revertFile(top, rel, items);
53
578
  }
54
- return changes.revertFile(top, rel, items);
579
+ return revertFile(top, rel, items);
55
580
  };
56
581
 
57
582
  const createGitRepo = () =>
@@ -59,22 +584,27 @@ const createGitRepo = () =>
59
584
  {
60
585
  load,
61
586
  loadAsync,
62
- loadExtras: dependencies.loadExtras,
63
- toplevel: read.toplevel,
64
- resolveRev: read.resolveRev,
65
- add: addItem,
66
- addAsync: addItemAsync,
67
- unstage: unstageItem,
68
- revert: revertItem,
69
- revertFile,
70
- edit: changes.editItem,
587
+ loadExtras: gitDeps.loadExtras,
588
+ toplevel,
589
+ resolveRev,
590
+ listFiles: listScopeFiles,
591
+ fileText,
592
+ add: addGitItem,
593
+ addAsync: addGitItemAsync,
594
+ unstage: unstageGitItem,
595
+ revert: revertGitItem,
596
+ revertFile: revertGitFile,
597
+ edit: editItem,
598
+ writeFile,
599
+ stagePath,
71
600
  commit: branches.commitChanges,
72
601
  commitAsync: branches.commitChangesAsync,
73
602
  hasStaged: branches.hasStaged,
74
603
  lastMessage: branches.lastMessage,
604
+ commitMessage: branches.commitMessage,
75
605
  listBranches: branches.listBranches,
76
606
  listCommits: branches.listCommits,
77
- currentBranch: read.currentBranch,
607
+ currentBranch,
78
608
  checkout: branches.checkoutBranch,
79
609
  checkoutAsync: branches.checkoutBranchAsync,
80
610
  createBranch: branches.createBranch,
@@ -85,6 +615,10 @@ const createGitRepo = () =>
85
615
  dropAsync: branches.dropBranchAsync,
86
616
  dropCommit: branches.dropCommit,
87
617
  dropCommitAsync: branches.dropCommitAsync,
618
+ applyFixup: branches.applyFixup,
619
+ applyFixupAsync: branches.applyFixupAsync,
620
+ reword: branches.rewordCommit,
621
+ rewordAsync: branches.rewordCommitAsync,
88
622
  pull: branches.pullChanges,
89
623
  pullAsync: branches.pullChangesAsync,
90
624
  push: branches.pushChanges,
@@ -93,34 +627,38 @@ const createGitRepo = () =>
93
627
  capabilitiesFor('local'),
94
628
  );
95
629
 
96
- module.exports = {
97
- load,
98
- loadAsync,
99
- loadExtras: dependencies.loadExtras,
100
- addItem,
101
- unstageItem,
102
- revertItem,
103
- editItem: changes.editItem,
104
- commitChanges: branches.commitChanges,
105
- commitChangesAsync: branches.commitChangesAsync,
106
- hasStaged: branches.hasStaged,
107
- currentBranch: read.currentBranch,
108
- lastMessage: branches.lastMessage,
109
- listBranches: branches.listBranches,
110
- listCommits: branches.listCommits,
111
- checkoutBranch: branches.checkoutBranch,
112
- checkoutBranchAsync: branches.checkoutBranchAsync,
113
- createBranch: branches.createBranch,
114
- createBranchAsync: branches.createBranchAsync,
115
- rebaseBranch: branches.rebaseBranch,
116
- rebaseBranchAsync: branches.rebaseBranchAsync,
117
- dropBranch: branches.dropBranch,
118
- dropBranchAsync: branches.dropBranchAsync,
119
- dropCommit: branches.dropCommit,
120
- dropCommitAsync: branches.dropCommitAsync,
121
- pullChanges: branches.pullChanges,
122
- pullChangesAsync: branches.pullChangesAsync,
123
- pushChanges: branches.pushChanges,
124
- pushChangesAsync: branches.pushChangesAsync,
125
- createGitRepo,
126
- };
630
+ module.exports.load = load;
631
+ module.exports.loadAsync = loadAsync;
632
+ module.exports.loadExtras = gitDeps.loadExtras;
633
+ module.exports.addItem = addGitItem;
634
+ module.exports.unstageItem = unstageGitItem;
635
+ module.exports.revertItem = revertGitItem;
636
+ module.exports.editItem = editItem;
637
+ module.exports.writeFile = writeFile;
638
+ module.exports.commitChanges = branches.commitChanges;
639
+ module.exports.commitChangesAsync = branches.commitChangesAsync;
640
+ module.exports.hasStaged = branches.hasStaged;
641
+ module.exports.currentBranch = currentBranch;
642
+ module.exports.lastMessage = branches.lastMessage;
643
+ module.exports.commitMessage = branches.commitMessage;
644
+ module.exports.listBranches = branches.listBranches;
645
+ module.exports.listCommits = branches.listCommits;
646
+ module.exports.checkoutBranch = branches.checkoutBranch;
647
+ module.exports.checkoutBranchAsync = branches.checkoutBranchAsync;
648
+ module.exports.createBranch = branches.createBranch;
649
+ module.exports.createBranchAsync = branches.createBranchAsync;
650
+ module.exports.rebaseBranch = branches.rebaseBranch;
651
+ module.exports.rebaseBranchAsync = branches.rebaseBranchAsync;
652
+ module.exports.dropBranch = branches.dropBranch;
653
+ module.exports.dropBranchAsync = branches.dropBranchAsync;
654
+ module.exports.dropCommit = branches.dropCommit;
655
+ module.exports.dropCommitAsync = branches.dropCommitAsync;
656
+ module.exports.applyFixup = branches.applyFixup;
657
+ module.exports.applyFixupAsync = branches.applyFixupAsync;
658
+ module.exports.rewordCommit = branches.rewordCommit;
659
+ module.exports.rewordCommitAsync = branches.rewordCommitAsync;
660
+ module.exports.pullChanges = branches.pullChanges;
661
+ module.exports.pullChangesAsync = branches.pullChangesAsync;
662
+ module.exports.pushChanges = branches.pushChanges;
663
+ module.exports.pushChangesAsync = branches.pushChangesAsync;
664
+ module.exports.createGitRepo = createGitRepo;