@laoyuehanni/dsh-git-worktree 0.4.8 → 0.4.10

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 (79) hide show
  1. package/README.md +5 -2
  2. package/README.zh.md +5 -2
  3. package/lib/client.js +2393 -205
  4. package/lib/git.d.ts +58 -11
  5. package/lib/git.js +197 -17
  6. package/lib/graph-preview/asciidoc-xKuVlNk6.js +5 -0
  7. package/lib/graph-preview/bat-Dx8nnxXE.js +5 -0
  8. package/lib/graph-preview/bibtex-BzgdqG3s.js +5 -0
  9. package/lib/graph-preview/c-BGpbtv2-.js +8 -0
  10. package/lib/graph-preview/clojure-DDsQ0FaV.js +5 -0
  11. package/lib/graph-preview/cmake-DPsCB_V6.js +5 -0
  12. package/lib/graph-preview/cpp-CBYrHpV9.js +27 -0
  13. package/lib/graph-preview/csharp-CFKaLbHg.js +5 -0
  14. package/lib/graph-preview/css-C6zsnaz5.js +8 -0
  15. package/lib/graph-preview/csv-DqIVFkK7.js +5 -0
  16. package/lib/graph-preview/dart-C6DUdjib.js +5 -0
  17. package/lib/graph-preview/diff-Blb4MjsC.js +5 -0
  18. package/lib/graph-preview/dotenv-Dkdv7Sm2.js +5 -0
  19. package/lib/graph-preview/elixir-D0Gskj1z.js +8 -0
  20. package/lib/graph-preview/erlang-BJwlUj8s.js +8 -0
  21. package/lib/graph-preview/fish-D7qAeWQz.js +5 -0
  22. package/lib/graph-preview/fsharp-MCvH12ek.js +8 -0
  23. package/lib/graph-preview/go-aXtTCanQ.js +5 -0
  24. package/lib/graph-preview/graphql-DBbDUzBC.js +19 -0
  25. package/lib/graph-preview/groovy-Bw2Ku4bU.js +5 -0
  26. package/lib/graph-preview/haskell-CfGsE1Cf.js +5 -0
  27. package/lib/graph-preview/hcl-DHg_Osgo.js +5 -0
  28. package/lib/graph-preview/html-DwZ-9Aol.js +15 -0
  29. package/lib/graph-preview/html-derivative-CdrGiVx_.js +8 -0
  30. package/lib/graph-preview/http-B769neBI.js +16 -0
  31. package/lib/graph-preview/ini-C24lZfdM.js +5 -0
  32. package/lib/graph-preview/java-B6HH4GJL.js +8 -0
  33. package/lib/graph-preview/javascript-BXA9Hfas.js +5 -0
  34. package/lib/graph-preview/julia--d6L9eAJ.js +19 -0
  35. package/lib/graph-preview/kotlin-BHE8CoV9.js +5 -0
  36. package/lib/graph-preview/latex-BsyjE6iS.js +12 -0
  37. package/lib/graph-preview/less-BzbdhFUi.js +5 -0
  38. package/lib/graph-preview/log-Dad54gsi.js +5 -0
  39. package/lib/graph-preview/lua-DL6V31K-.js +10 -0
  40. package/lib/graph-preview/make-B2ukzWs3.js +5 -0
  41. package/lib/graph-preview/markdown-CkmxmzqY.js +5 -0
  42. package/lib/graph-preview/mdx-BK9ZufRc.js +5 -0
  43. package/lib/graph-preview/nix-BRl3YduB.js +9 -0
  44. package/lib/graph-preview/perl-DJHPR3L5.js +19 -0
  45. package/lib/graph-preview/php-B74oGaLi.js +21 -0
  46. package/lib/graph-preview/powershell-DvOBVZPr.js +5 -0
  47. package/lib/graph-preview/preview.js +79431 -0
  48. package/lib/graph-preview/proto-ClkOcAW0.js +5 -0
  49. package/lib/graph-preview/python-BjnOIxPe.js +5 -0
  50. package/lib/graph-preview/r-BSNufAtJ.js +8 -0
  51. package/lib/graph-preview/rst-CDCHc-qO.js +25 -0
  52. package/lib/graph-preview/ruby-Dx4dTqam.js +40 -0
  53. package/lib/graph-preview/rust-COBzcmTx.js +5 -0
  54. package/lib/graph-preview/scala-pMGZAs9j.js +5 -0
  55. package/lib/graph-preview/scss-D2N2uO1z.js +8 -0
  56. package/lib/graph-preview/sql-DBa5L-Wg.js +8 -0
  57. package/lib/graph-preview/svelte-DQXUqa3J.js +18 -0
  58. package/lib/graph-preview/swift-DWmMn3lF.js +5 -0
  59. package/lib/graph-preview/system-verilog-DW0KSMVO.js +5 -0
  60. package/lib/graph-preview/toml-B7BHZIqX.js +5 -0
  61. package/lib/graph-preview/vb-eGVhCUXq.js +5 -0
  62. package/lib/graph-preview/verilog-Ma7yBE30.js +5 -0
  63. package/lib/graph-preview/vue-k6e1qQTO.js +32 -0
  64. package/lib/graph-preview/xml-DUa-g8pJ.js +10 -0
  65. package/lib/graph-preview/yaml-B81N8prR.js +5 -0
  66. package/lib/history.d.ts +7 -0
  67. package/lib/history.js +79 -0
  68. package/lib/index.js +28 -4
  69. package/lib/progress.d.ts +60 -0
  70. package/lib/progress.js +122 -0
  71. package/lib/push.d.ts +27 -0
  72. package/lib/push.js +215 -0
  73. package/lib/routes.d.ts +48 -6
  74. package/lib/routes.js +149 -7
  75. package/lib/stream.d.ts +33 -0
  76. package/lib/stream.js +54 -0
  77. package/lib/wire.d.ts +131 -2
  78. package/lib/wire.js +18 -2
  79. package/package.json +12 -10
package/lib/git.d.ts CHANGED
@@ -9,14 +9,30 @@ export interface ExecResult {
9
9
  code: number;
10
10
  stdout: string;
11
11
  stderr: string;
12
+ /** The run was stopped by its `signal` (set by a live run only). */
13
+ cancelled?: boolean;
14
+ }
15
+ /** Options of one {@link Exec} call. */
16
+ export interface ExecOptions {
17
+ cwd: string;
18
+ /** Hard cap on the whole run. Absent = 20 s for a plain run, none for a
19
+ * live one (which is bounded by `idleTimeoutMs` and its `signal`). */
20
+ timeoutMs?: number;
21
+ nonInteractive?: boolean;
22
+ /** Live run: git's stdout and stderr text, chunk by chunk as it is written.
23
+ * Any of the three live options moves the run onto a streaming spawn. */
24
+ onOutput?: (chunk: string) => void;
25
+ /** Live run: aborting kills git and its transport children and answers
26
+ * `cancelled`. */
27
+ signal?: AbortSignal;
28
+ /** Live run: kill git after this long without a byte of output. */
29
+ idleTimeoutMs?: number;
12
30
  }
13
31
  /**
14
32
  * Process executor seam. Runs `file args` with cwd set, captures output as
15
33
  * UTF-8 text, and never throws — a non-zero exit is a normal result.
16
34
  */
17
- export type Exec = (file: string, args: readonly string[], options: {
18
- cwd: string;
19
- }) => Promise<ExecResult>;
35
+ export type Exec = (file: string, args: readonly string[], options: ExecOptions) => Promise<ExecResult>;
20
36
  /** Failure of one git invocation: non-zero exit with the stderr text. */
21
37
  export declare class GitError extends Error {
22
38
  readonly args: readonly string[];
@@ -48,10 +64,9 @@ export interface RepoFacts {
48
64
  branches: BranchEntry[];
49
65
  worktrees: WorktreeEntry[];
50
66
  }
51
- /** Real executor over node:child_process with a hard timeout. */
52
- export declare function childProcessExec(file: string, args: readonly string[], options: {
53
- cwd: string;
54
- }): Promise<ExecResult>;
67
+ /** Real executor over node:child_process: a buffered run with a hard timeout,
68
+ * or — when the caller asks for live output / cancellation — a streaming one. */
69
+ export declare function childProcessExec(file: string, args: readonly string[], options: ExecOptions): Promise<ExecResult>;
55
70
  /** Directory-existence seam over the parsed worktree registrations. */
56
71
  export type DirExists = (path: string) => boolean;
57
72
  /** Real existence check. */
@@ -193,12 +208,43 @@ export declare function deleteBranch(exec: Exec, repoRoot: string, name: string)
193
208
  * Sync remote-tracking refs: fetch every remote and prune tracking branches
194
209
  * the remotes no longer carry (the CLI equivalent of IDEA's "synchronize
195
210
  * remote branches"). Pure metadata — the working tree, local branches, and
196
- * the current checkout are untouched; a slow network surfaces through the
197
- * executor's hard timeout as a GitError.
211
+ * the current checkout are untouched. A plain call is bounded by the
212
+ * executor's hard timeout; a {@link LiveRun} lifts that for a transfer the
213
+ * user can watch and cancel.
198
214
  * @param exec - executor seam.
199
215
  * @param repoRoot - main worktree directory (fetch is repository-wide).
216
+ * @param live - optional live output / cancellation of this run.
200
217
  */
201
- export declare function fetchAll(exec: Exec, repoRoot: string): Promise<void>;
218
+ export declare function fetchAll(exec: Exec, repoRoot: string, live?: LiveRun): Promise<void>;
219
+ /** A live run's patience with a silent git: long enough for a remote that
220
+ * takes minutes to enumerate a huge repository (or a pre-push hook that runs
221
+ * the test suite), short enough that a stuck connection is not left spinning
222
+ * for good. */
223
+ export declare const LIVE_IDLE_TIMEOUT_MS: number;
224
+ /**
225
+ * The executor options that make one git run live: no whole-run cap, only
226
+ * {@link LIVE_IDLE_TIMEOUT_MS} of silence, plus the caller's output sink and
227
+ * cancellation signal.
228
+ * @param live - the run's live channel.
229
+ * @returns options to spread into an {@link Exec} call (next to `cwd`).
230
+ */
231
+ export declare function liveExecOptions(live: LiveRun): Pick<ExecOptions, 'idleTimeoutMs' | 'onOutput' | 'signal'>;
232
+ /** Watching and stopping one long git run (a fetch the UI shows progress for). */
233
+ export interface LiveRun {
234
+ /** git's stdout and stderr text as it is written. */
235
+ onOutput?: (chunk: string) => void;
236
+ /** The fetch moves on to this remote; its output follows. */
237
+ onRemote?: (remote: string) => void;
238
+ /** Aborting kills git; the call then throws {@link CancelledError}. */
239
+ signal?: AbortSignal;
240
+ /** The fetch is over and the fast-forward begins — the last step, which
241
+ * is quick and not worth interrupting half way. */
242
+ onMerge?: () => void;
243
+ }
244
+ /** A live run its caller aborted — not a failure anyone needs to hear about. */
245
+ export declare class CancelledError extends Error {
246
+ constructor();
247
+ }
202
248
  /** Outcome of {@link updateBranch}: the branch touched and whether it moved. */
203
249
  export interface UpdateOutcome {
204
250
  branch: string;
@@ -215,10 +261,11 @@ export interface UpdateOutcome {
215
261
  * branch ITS worktree holds.
216
262
  * @param exec - executor seam.
217
263
  * @param cwd - directory whose checked-out branch is updated.
264
+ * @param live - optional live output / cancellation of the fetch step.
218
265
  * @returns the branch name and whether HEAD actually moved (false = the
219
266
  * upstream already contained it).
220
267
  */
221
- export declare function updateBranch(exec: Exec, cwd: string): Promise<UpdateOutcome>;
268
+ export declare function updateBranch(exec: Exec, cwd: string, live?: LiveRun): Promise<UpdateOutcome>;
222
269
  /** Guard for route inputs: a non-empty absolute directory path. */
223
270
  export declare function isAbsoluteDir(value: string): boolean;
224
271
  /** Pre-delete facts of one worktree directory, for the remove-confirm dialog. */
package/lib/git.js CHANGED
@@ -3,11 +3,12 @@
3
3
  * injectable `exec` seam (tests substitute it); every method is plain
4
4
  * argument assembly plus porcelain parsing, no ambient state.
5
5
  */
6
- import { execFile } from 'node:child_process';
6
+ import { execFile, spawn } from 'node:child_process';
7
7
  import { existsSync, readdirSync } from 'node:fs';
8
8
  import { appendFile, mkdir, readFile, rm } from 'node:fs/promises';
9
9
  import { basename, dirname, isAbsolute, join, normalize, resolve } from 'node:path';
10
10
  import { localBranchName } from './normalize.js';
11
+ import { stripProgress } from './progress.js';
11
12
  /** Failure of one git invocation: non-zero exit with the stderr text. */
12
13
  export class GitError extends Error {
13
14
  args;
@@ -21,17 +22,116 @@ export class GitError extends Error {
21
22
  this.name = 'GitError';
22
23
  }
23
24
  }
24
- /** Real executor over node:child_process with a hard timeout. */
25
+ /** Appended to the stderr of a run that was killed for taking too long. */
26
+ const TIMED_OUT = 'Git command timed out; check the remote before retrying.';
27
+ /** Environment of one run: `nonInteractive` stops git (and its credential
28
+ * helper) from waiting on a prompt nobody can answer. */
29
+ function execEnv(options) {
30
+ return options.nonInteractive ? { env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'never' } } : {};
31
+ }
32
+ /** Real executor over node:child_process: a buffered run with a hard timeout,
33
+ * or — when the caller asks for live output / cancellation — a streaming one. */
25
34
  export function childProcessExec(file, args, options) {
35
+ if (options.onOutput !== undefined || options.signal !== undefined || options.idleTimeoutMs !== undefined) {
36
+ return liveProcessExec(file, args, options);
37
+ }
26
38
  return new Promise((resolvePromise) => {
27
- execFile(file, args, { cwd: options.cwd, encoding: 'utf8', timeout: 20_000, windowsHide: true, maxBuffer: 4 * 1024 * 1024 }, (error, stdout, stderr) => {
39
+ execFile(file, args, { cwd: options.cwd, encoding: 'utf8', timeout: options.timeoutMs ?? 20_000, windowsHide: true, maxBuffer: 4 * 1024 * 1024,
40
+ ...execEnv(options),
41
+ }, (error, stdout, stderr) => {
28
42
  // execFile reports any failure (non-zero exit, spawn error, timeout) as
29
43
  // a truthy error; the specific exit code never carries signal here —
30
44
  // stderr does — so every failure collapses to 1.
31
- resolvePromise({ code: error !== null ? 1 : 0, stdout: stdout ?? '', stderr: stderr ?? '' });
45
+ resolvePromise({ code: error !== null ? 1 : 0, stdout: stdout ?? '', stderr: error?.killed ? `${stderr ?? ''}\n${TIMED_OUT}` : stderr || error?.message || '' });
32
46
  });
33
47
  });
34
48
  }
49
+ /** What a live run keeps of each stream: git's progress redraws can run to
50
+ * megabytes, but only the head of stdout and the tail of stderr (where the
51
+ * failure is) are ever read back. */
52
+ const STDOUT_KEEP = 1024 * 1024;
53
+ const STDERR_KEEP = 256 * 1024;
54
+ /**
55
+ * Stop git AND the transport processes it started. `child.kill()` alone
56
+ * leaves them running on Windows (it is TerminateProcess on one pid), so a
57
+ * cancelled fetch would keep downloading in the background; POSIX git cleans
58
+ * up its own children on SIGTERM.
59
+ */
60
+ function killProcessTree(child) {
61
+ if (child.pid === undefined || child.exitCode !== null)
62
+ return;
63
+ if (process.platform === 'win32') {
64
+ const killer = spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
65
+ killer.on('error', () => { child.kill(); });
66
+ return;
67
+ }
68
+ child.kill('SIGTERM');
69
+ }
70
+ /** Streaming executor: reports output as it arrives and honours a signal. */
71
+ function liveProcessExec(file, args, options) {
72
+ return new Promise((resolvePromise) => {
73
+ if (options.signal?.aborted) {
74
+ resolvePromise({ code: 1, stdout: '', stderr: '', cancelled: true });
75
+ return;
76
+ }
77
+ const child = spawn(file, args, { cwd: options.cwd, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'], ...execEnv(options) });
78
+ let stdout = '';
79
+ let stderr = '';
80
+ let cancelled = false;
81
+ let timedOut = false;
82
+ let settled = false;
83
+ let idleTimer;
84
+ let hardTimer;
85
+ const result = (code) => ({
86
+ code: cancelled || timedOut ? 1 : code,
87
+ stdout,
88
+ stderr: timedOut ? `${stderr}\n${TIMED_OUT}` : stderr,
89
+ ...cancelled ? { cancelled: true } : {},
90
+ });
91
+ const settle = (outcome) => {
92
+ if (settled)
93
+ return;
94
+ settled = true;
95
+ clearTimeout(idleTimer);
96
+ clearTimeout(hardTimer);
97
+ options.signal?.removeEventListener('abort', onAbort);
98
+ resolvePromise(outcome);
99
+ };
100
+ const stop = () => { killProcessTree(child); };
101
+ const onAbort = () => { cancelled = true; stop(); };
102
+ const armIdle = () => {
103
+ if (options.idleTimeoutMs === undefined)
104
+ return;
105
+ clearTimeout(idleTimer);
106
+ idleTimer = setTimeout(() => { timedOut = true; stop(); }, options.idleTimeoutMs);
107
+ };
108
+ options.signal?.addEventListener('abort', onAbort, { once: true });
109
+ if (options.timeoutMs !== undefined)
110
+ hardTimer = setTimeout(() => { timedOut = true; stop(); }, options.timeoutMs);
111
+ armIdle();
112
+ child.stdout.setEncoding('utf8');
113
+ child.stderr.setEncoding('utf8');
114
+ child.stdout.on('data', (chunk) => {
115
+ if (stdout.length < STDOUT_KEEP)
116
+ stdout += chunk;
117
+ armIdle();
118
+ options.onOutput?.(chunk);
119
+ });
120
+ child.stderr.on('data', (chunk) => {
121
+ stderr += chunk;
122
+ if (stderr.length > STDERR_KEEP * 2)
123
+ stderr = stderr.slice(-STDERR_KEEP);
124
+ armIdle();
125
+ options.onOutput?.(chunk);
126
+ });
127
+ child.on('error', (error) => { settle({ code: 1, stdout, stderr: stderr || error.message }); });
128
+ // A killed run settles on exit: a transport grandchild that outlived the
129
+ // kill could hold the pipes open and postpone `close` indefinitely.
130
+ child.on('exit', (code) => { if (cancelled || timedOut)
131
+ settle(result(code ?? 1)); });
132
+ child.on('close', (code) => { settle(result(code ?? 1)); });
133
+ });
134
+ }
35
135
  /** Run one git command; a non-zero exit raises {@link GitError} with stderr. */
36
136
  async function git(exec, cwd, args) {
37
137
  const result = await exec('git', args, { cwd });
@@ -155,17 +255,16 @@ async function currentBranch(exec, cwd) {
155
255
  * exists) plus remote-only branches across EVERY remote (`<remote>/HEAD`
156
256
  * dropped).
157
257
  *
158
- * The upstream track comes from `%(upstream:track)`, which renders
159
- * `[ahead N, behind M]` (or a bare `[gone]`) directly after the refname —
160
- * `[` is illegal in refnames, so `indexOf('[')` splits name from track
161
- * without a separator. `[gone]` (upstream deleted server-side) carries no
162
- * counts and is dropped here; the UI renders no marker for it.
258
+ * Track follows the refname (`[` is forbidden in refs); a tab separates
259
+ * the configured upstream. Keeping the upstream and [gone] fact lets the
260
+ * UI distinguish unpublished branches from synchronized and deleted ones.
163
261
  */
164
262
  async function listBranches(exec, repoRoot) {
165
- const localOut = await git(exec, repoRoot, ['for-each-ref', 'refs/heads', '--format=%(refname:short)%(upstream:track)']);
263
+ const localOut = await git(exec, repoRoot, ['for-each-ref', 'refs/heads', '--format=%(refname:short)%(upstream:track)%09%(upstream:short)']);
166
264
  const entries = [];
167
265
  for (const line of localOut.split('\n')) {
168
- const trimmed = line.trim();
266
+ const [label = '', upstream = ''] = line.split('\t');
267
+ const trimmed = label.trim();
169
268
  if (trimmed === '')
170
269
  continue;
171
270
  const bracket = trimmed.indexOf('[');
@@ -176,6 +275,10 @@ async function listBranches(exec, repoRoot) {
176
275
  const ahead = /\bahead (\d+)/.exec(track);
177
276
  const behind = /\bbehind (\d+)/.exec(track);
178
277
  const entry = { name, kind: 'local' };
278
+ if (upstream !== '')
279
+ entry.upstream = upstream.trim();
280
+ if (track === '[gone]')
281
+ entry.upstreamGone = true;
179
282
  if (ahead !== null)
180
283
  entry.ahead = Number(ahead[1]);
181
284
  if (behind !== null)
@@ -442,13 +545,84 @@ export async function deleteBranch(exec, repoRoot, name) {
442
545
  * Sync remote-tracking refs: fetch every remote and prune tracking branches
443
546
  * the remotes no longer carry (the CLI equivalent of IDEA's "synchronize
444
547
  * remote branches"). Pure metadata — the working tree, local branches, and
445
- * the current checkout are untouched; a slow network surfaces through the
446
- * executor's hard timeout as a GitError.
548
+ * the current checkout are untouched. A plain call is bounded by the
549
+ * executor's hard timeout; a {@link LiveRun} lifts that for a transfer the
550
+ * user can watch and cancel.
447
551
  * @param exec - executor seam.
448
552
  * @param repoRoot - main worktree directory (fetch is repository-wide).
553
+ * @param live - optional live output / cancellation of this run.
554
+ */
555
+ export async function fetchAll(exec, repoRoot, live) {
556
+ if (live === undefined) {
557
+ await git(exec, repoRoot, FETCH_ARGS);
558
+ return;
559
+ }
560
+ // One fetch per remote instead of `--all --progress`: with several remotes
561
+ // git runs a child per remote and never hands it `--progress`, so the
562
+ // counters would silently vanish exactly in the fork setups that have them.
563
+ // Like `--all`, a failing remote does not stop the others.
564
+ let failure;
565
+ for (const remote of await fetchableRemotes(exec, repoRoot)) {
566
+ live.onRemote?.(remote);
567
+ // `--progress` because git only draws its counters on a terminal otherwise.
568
+ const result = await exec('git', ['fetch', remote, '--prune', '--progress'], { cwd: repoRoot, ...liveExecOptions(live) });
569
+ if (result.cancelled)
570
+ throw new CancelledError();
571
+ if (result.code !== 0) {
572
+ failure ??= { code: result.code, messages: [] };
573
+ // git's words without the thousand progress redraws before them.
574
+ failure.messages.push(stripProgress(result.stderr));
575
+ }
576
+ }
577
+ // The error names the command the user knows, not the per-remote plumbing.
578
+ if (failure !== undefined)
579
+ throw new GitError(FETCH_ARGS, failure.code, failure.messages.join('\n'));
580
+ }
581
+ /** The fetch every plain sync runs. */
582
+ const FETCH_ARGS = ['fetch', '--all', '--prune'];
583
+ /**
584
+ * The remotes `git fetch --all` would visit: all of them except those marked
585
+ * `remote.<name>.skipFetchAll` — a live run walks them itself.
586
+ * @param exec - executor seam.
587
+ * @param repoRoot - main worktree directory.
588
+ * @returns remote names, in git's order.
449
589
  */
450
- export async function fetchAll(exec, repoRoot) {
451
- await git(exec, repoRoot, ['fetch', '--all', '--prune']);
590
+ async function fetchableRemotes(exec, repoRoot) {
591
+ const names = (await git(exec, repoRoot, ['remote'])).split('\n').map(line => line.trim()).filter(line => line !== '');
592
+ const flags = await gitMaybe(exec, repoRoot, ['config', '--bool', '--get-regexp', '^remote\\..+\\.skipfetchall$']);
593
+ const skipped = new Set();
594
+ for (const line of (flags ?? '').split('\n')) {
595
+ const name = /^remote\.(.+)\.skipfetchall\s+true$/i.exec(line.trim())?.[1];
596
+ if (name !== undefined)
597
+ skipped.add(name);
598
+ }
599
+ return names.filter(name => !skipped.has(name));
600
+ }
601
+ /** A live run's patience with a silent git: long enough for a remote that
602
+ * takes minutes to enumerate a huge repository (or a pre-push hook that runs
603
+ * the test suite), short enough that a stuck connection is not left spinning
604
+ * for good. */
605
+ export const LIVE_IDLE_TIMEOUT_MS = 5 * 60_000;
606
+ /**
607
+ * The executor options that make one git run live: no whole-run cap, only
608
+ * {@link LIVE_IDLE_TIMEOUT_MS} of silence, plus the caller's output sink and
609
+ * cancellation signal.
610
+ * @param live - the run's live channel.
611
+ * @returns options to spread into an {@link Exec} call (next to `cwd`).
612
+ */
613
+ export function liveExecOptions(live) {
614
+ return {
615
+ idleTimeoutMs: LIVE_IDLE_TIMEOUT_MS,
616
+ ...live.onOutput === undefined ? {} : { onOutput: live.onOutput },
617
+ ...live.signal === undefined ? {} : { signal: live.signal },
618
+ };
619
+ }
620
+ /** A live run its caller aborted — not a failure anyone needs to hear about. */
621
+ export class CancelledError extends Error {
622
+ constructor() {
623
+ super('Cancelled');
624
+ this.name = 'CancelledError';
625
+ }
452
626
  }
453
627
  /**
454
628
  * Update the CURRENT checkout: fetch every remote, then fast-forward the
@@ -461,11 +635,17 @@ export async function fetchAll(exec, repoRoot) {
461
635
  * branch ITS worktree holds.
462
636
  * @param exec - executor seam.
463
637
  * @param cwd - directory whose checked-out branch is updated.
638
+ * @param live - optional live output / cancellation of the fetch step.
464
639
  * @returns the branch name and whether HEAD actually moved (false = the
465
640
  * upstream already contained it).
466
641
  */
467
- export async function updateBranch(exec, cwd) {
468
- await fetchAll(exec, cwd);
642
+ export async function updateBranch(exec, cwd, live) {
643
+ await fetchAll(exec, cwd, live);
644
+ // Cancelled in the instant between the fetch ending and now: honour it,
645
+ // never move the user's branch after they said stop.
646
+ if (live?.signal?.aborted)
647
+ throw new CancelledError();
648
+ live?.onMerge?.();
469
649
  const before = (await git(exec, cwd, ['rev-parse', 'HEAD'])).trim();
470
650
  await git(exec, cwd, ['merge', '--ff-only', '@{u}']);
471
651
  const after = (await git(exec, cwd, ['rev-parse', 'HEAD'])).trim();