@laoyuehanni/dsh-git-worktree 0.4.7 → 0.4.9
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 +4 -2
- package/README.zh.md +4 -2
- package/lib/client.js +1704 -104
- package/lib/git.d.ts +58 -11
- package/lib/git.js +197 -17
- package/lib/head.d.ts +33 -0
- package/lib/head.js +152 -0
- package/lib/index.js +30 -5
- package/lib/progress.d.ts +60 -0
- package/lib/progress.js +122 -0
- package/lib/push.d.ts +27 -0
- package/lib/push.js +215 -0
- package/lib/routes.d.ts +51 -6
- package/lib/routes.js +136 -7
- package/lib/stream.d.ts +33 -0
- package/lib/stream.js +54 -0
- package/lib/wire.d.ts +114 -2
- package/lib/wire.js +18 -2
- package/package.json +12 -10
package/lib/routes.js
CHANGED
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
6
6
|
import { mkdir, readdir, rm, stat } from 'node:fs/promises';
|
|
7
7
|
import { runPostCreateCopy } from './copy-files.js';
|
|
8
|
-
import { appendWorktreeExclude, fsExcludeSeams, GitError, addWorktree, addWorktreeCutout, createBranch, cutoutBranchName, deleteBranch, fetchAll, fsDirExists, inspectWorktree, isAbsoluteDir, probeRepo, probeWorkspaceGit, removeWorktree, renameBranch, resolveBranch, switchBranch, updateBranch } from './git.js';
|
|
8
|
+
import { appendWorktreeExclude, fsExcludeSeams, CancelledError, GitError, addWorktree, addWorktreeCutout, createBranch, cutoutBranchName, deleteBranch, fetchAll, fsDirExists, inspectWorktree, isAbsoluteDir, probeRepo, probeWorkspaceGit, removeWorktree, renameBranch, resolveBranch, switchBranch, updateBranch } from './git.js';
|
|
9
|
+
import { readCheckedOutBranch } from './head.js';
|
|
10
|
+
import { openPush, previewPush, pushBranch } from './push.js';
|
|
9
11
|
import { isAbsoluteConfigPath, sanitizeBranchDir } from './normalize.js';
|
|
12
|
+
import { createProgressReader } from './progress.js';
|
|
10
13
|
import { resolveRootDir } from './settings.js';
|
|
11
14
|
/** Real fs-backed one-level directory listing (names only). Plain FILES are
|
|
12
15
|
* filtered out — the storage root can carry strays (a legacy settings.json
|
|
@@ -326,6 +329,21 @@ export async function handleStatus(deps, path) {
|
|
|
326
329
|
},
|
|
327
330
|
};
|
|
328
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* GET /head — the checked-out branch of one directory, from the HEAD file.
|
|
334
|
+
* `pending` is a skipped tick: the caller keeps the label it already has.
|
|
335
|
+
* @param path - absolute directory the workspace reports.
|
|
336
|
+
*/
|
|
337
|
+
export async function handleHead(path) {
|
|
338
|
+
if (path === undefined || !isAbsoluteDir(path))
|
|
339
|
+
return fail(400, 'query parameter "path" must be an absolute directory');
|
|
340
|
+
const read = await readCheckedOutBranch(path);
|
|
341
|
+
if (read.kind === 'absent')
|
|
342
|
+
return { status: 200, body: { repo: false } };
|
|
343
|
+
if (read.kind === 'unread')
|
|
344
|
+
return { status: 200, body: { repo: true, pending: true } };
|
|
345
|
+
return { status: 200, body: { repo: true, currentBranch: read.name } };
|
|
346
|
+
}
|
|
329
347
|
/** Validate a JSON body object with exactly the expected keys. */
|
|
330
348
|
function readBody(body, keys, booleanKeys = [], optionalKeys = []) {
|
|
331
349
|
if (typeof body !== 'object' || body === null || Array.isArray(body))
|
|
@@ -618,49 +636,155 @@ export async function handleDeleteBranch(deps, body) {
|
|
|
618
636
|
}
|
|
619
637
|
}
|
|
620
638
|
/**
|
|
621
|
-
*
|
|
639
|
+
* Translate a route's live channel into a git {@link LiveRun}: git's raw
|
|
640
|
+
* output goes through the progress reader, so the caller sees structured,
|
|
641
|
+
* throttled events instead of a thousand `\r` redraws.
|
|
642
|
+
* @param live - the route's channel; absent for a plain, non-streamed call.
|
|
643
|
+
* @returns the run to hand to git (undefined = no live behaviour) and `end`,
|
|
644
|
+
* which flushes the reader's last held observation.
|
|
645
|
+
*/
|
|
646
|
+
function startLive(live) {
|
|
647
|
+
if (live === undefined)
|
|
648
|
+
return { run: undefined, end: () => undefined };
|
|
649
|
+
const reader = createProgressReader(progress => { live.emit({ type: 'progress', ...progress }); });
|
|
650
|
+
return {
|
|
651
|
+
run: {
|
|
652
|
+
onOutput: (chunk) => { reader.feed(chunk); },
|
|
653
|
+
onRemote: (remote) => { reader.remote(remote); },
|
|
654
|
+
signal: live.signal,
|
|
655
|
+
// The merge event must come after the last progress line, not before.
|
|
656
|
+
onMerge: () => { reader.end(); live.emit({ type: 'merge' }); },
|
|
657
|
+
},
|
|
658
|
+
end: () => { reader.end(); },
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* POST /fetch — sync remote-tracking refs for the repository: fetch every
|
|
622
663
|
* remote and prune tracking branches the remotes no longer carry. Pure
|
|
623
664
|
* metadata — the working tree and the current checkout are untouched; the
|
|
624
665
|
* client refetches /status afterwards for the fresh branch list.
|
|
625
666
|
* @param deps - host dependencies.
|
|
626
667
|
* @param body - parsed request body.
|
|
668
|
+
* @param live - the streaming channel (absent = the plain request).
|
|
627
669
|
*/
|
|
628
|
-
export async function handleFetch(deps, body) {
|
|
670
|
+
export async function handleFetch(deps, body, live) {
|
|
629
671
|
const parsed = readBody(body, ['repoPath']);
|
|
630
672
|
if (isOutcome(parsed))
|
|
631
673
|
return parsed;
|
|
632
674
|
const { repoPath } = parsed;
|
|
633
675
|
if (!isAbsoluteDir(repoPath))
|
|
634
676
|
return fail(400, '"repoPath" must be an absolute directory');
|
|
677
|
+
const { run, end } = startLive(live);
|
|
635
678
|
try {
|
|
636
679
|
const facts = await probeRepo(deps.exec, repoPath, deps.dirExists);
|
|
637
680
|
if (facts === undefined)
|
|
638
681
|
return fail(400, `"${repoPath}" is not inside a git repository`);
|
|
639
|
-
await fetchAll(deps.exec, facts.repoRoot);
|
|
682
|
+
await fetchAll(deps.exec, facts.repoRoot, run);
|
|
640
683
|
const result = { remote: 'all' };
|
|
641
684
|
return { status: 200, body: result };
|
|
642
685
|
}
|
|
643
686
|
catch (error) {
|
|
687
|
+
if (error instanceof CancelledError)
|
|
688
|
+
return fail(499, error.message);
|
|
644
689
|
if (error instanceof GitError)
|
|
645
690
|
return gitFailure(error);
|
|
646
691
|
return fail(500, error instanceof Error ? error.message : String(error));
|
|
647
692
|
}
|
|
693
|
+
finally {
|
|
694
|
+
end();
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* POST /push-plan — read-only destination resolution for one local branch,
|
|
699
|
+
* bundled with a display-only local snapshot of what it would push (see
|
|
700
|
+
* `openPush`). Publishing is a separate explicit POST.
|
|
701
|
+
* @param deps - host dependencies.
|
|
702
|
+
* @param body - parsed request body: `{ repoPath, branch }`.
|
|
703
|
+
*/
|
|
704
|
+
export async function handlePushPlan(deps, body) {
|
|
705
|
+
return handlePushAction(deps, body, false);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* POST /push — push one explicit local branch to an explicit destination
|
|
709
|
+
* (or, without one, to the confirmation-free default of `planPush`).
|
|
710
|
+
* @param deps - host dependencies.
|
|
711
|
+
* @param body - parsed request body.
|
|
712
|
+
* @param live - the streaming channel (absent = the plain request, which
|
|
713
|
+
* keeps its two-minute cap).
|
|
714
|
+
*/
|
|
715
|
+
export async function handlePush(deps, body, live) {
|
|
716
|
+
return handlePushAction(deps, body, true, live);
|
|
648
717
|
}
|
|
649
718
|
/**
|
|
650
|
-
* POST /
|
|
719
|
+
* POST /push-preview — the commits one explicit remote/target would receive,
|
|
720
|
+
* read from the real push destination (or from local tracking refs with
|
|
721
|
+
* `localOnly`, which never touches the network). Pushes nothing.
|
|
722
|
+
* @param deps - host dependencies.
|
|
723
|
+
* @param body - parsed request body.
|
|
724
|
+
*/
|
|
725
|
+
export async function handlePushPreview(deps, body) {
|
|
726
|
+
const parsed = readBody(body, ['repoPath', 'branch', 'remote', 'target'], ['localOnly']);
|
|
727
|
+
if (isOutcome(parsed))
|
|
728
|
+
return parsed;
|
|
729
|
+
if (!isAbsoluteDir(parsed.repoPath) || !parsed.branch.trim() || !parsed.remote?.trim() || !parsed.target?.trim())
|
|
730
|
+
return fail(400, 'An absolute repoPath, branch, remote and target are required');
|
|
731
|
+
try {
|
|
732
|
+
return { status: 200, body: await previewPush(deps.exec, parsed.repoPath, { ...parsed, remote: parsed.remote, target: parsed.target }) };
|
|
733
|
+
}
|
|
734
|
+
catch (error) {
|
|
735
|
+
return fail(400, error instanceof Error ? error.message : String(error));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
async function handlePushAction(deps, body, execute, live) {
|
|
739
|
+
const parsed = readBody(body, ['repoPath', 'branch'], execute ? ['force'] : [], execute ? ['remote', 'target', 'tags', 'expectedTarget', 'sourceOid'] : []);
|
|
740
|
+
if (isOutcome(parsed))
|
|
741
|
+
return parsed;
|
|
742
|
+
if (!isAbsoluteDir(parsed.repoPath))
|
|
743
|
+
return fail(400, '"repoPath" must be an absolute directory');
|
|
744
|
+
if (parsed.branch.trim() === '')
|
|
745
|
+
return fail(400, '"branch" must be non-empty');
|
|
746
|
+
if (parsed.tags !== undefined && !['none', 'all', 'follow'].includes(parsed.tags))
|
|
747
|
+
return fail(400, '"tags" must be none, all or follow');
|
|
748
|
+
if (parsed.sourceOid !== undefined && !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(parsed.sourceOid))
|
|
749
|
+
return fail(400, '"sourceOid" must be a full object ID');
|
|
750
|
+
if ((parsed.remote === undefined) !== (parsed.target === undefined))
|
|
751
|
+
return fail(400, '"remote" and "target" must be provided together');
|
|
752
|
+
if (parsed.remote !== undefined && (typeof parsed.remote !== 'string' || parsed.remote.trim() === ''
|
|
753
|
+
|| typeof parsed.target !== 'string' || parsed.target.trim() === ''))
|
|
754
|
+
return fail(400, '"remote" and "target" must be non-empty strings');
|
|
755
|
+
const { run, end } = startLive(execute ? live : undefined);
|
|
756
|
+
try {
|
|
757
|
+
return { status: 200, body: execute
|
|
758
|
+
? await pushBranch(deps.exec, parsed.repoPath, parsed, run)
|
|
759
|
+
: await openPush(deps.exec, parsed.repoPath, parsed.branch) };
|
|
760
|
+
}
|
|
761
|
+
catch (error) {
|
|
762
|
+
// Stopped by the caller: not a failure, and nobody is left to read it.
|
|
763
|
+
if (error instanceof CancelledError)
|
|
764
|
+
return fail(499, error.message);
|
|
765
|
+
return fail(400, error instanceof Error ? error.message : String(error));
|
|
766
|
+
}
|
|
767
|
+
finally {
|
|
768
|
+
end();
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* POST /update — update the CURRENT checkout: fetch every remote, then
|
|
651
773
|
* fast-forward the branch checked out by the queried directory to its
|
|
652
774
|
* upstream. Divergence, a missing upstream, and conflicting working-tree
|
|
653
775
|
* changes all surface as 400 envelopes carrying git's own explanation.
|
|
654
776
|
* @param deps - host dependencies.
|
|
655
777
|
* @param body - parsed request body.
|
|
778
|
+
* @param live - the streaming channel (absent = the plain request).
|
|
656
779
|
*/
|
|
657
|
-
export async function handleUpdate(deps, body) {
|
|
780
|
+
export async function handleUpdate(deps, body, live) {
|
|
658
781
|
const parsed = readBody(body, ['repoPath']);
|
|
659
782
|
if (isOutcome(parsed))
|
|
660
783
|
return parsed;
|
|
661
784
|
const { repoPath } = parsed;
|
|
662
785
|
if (!isAbsoluteDir(repoPath))
|
|
663
786
|
return fail(400, '"repoPath" must be an absolute directory');
|
|
787
|
+
const { run, end } = startLive(live);
|
|
664
788
|
try {
|
|
665
789
|
const facts = await probeRepo(deps.exec, repoPath, deps.dirExists);
|
|
666
790
|
if (facts === undefined)
|
|
@@ -669,15 +793,20 @@ export async function handleUpdate(deps, body) {
|
|
|
669
793
|
// session "update current branch" means the branch that worktree holds.
|
|
670
794
|
// `repoRoot` would fast-forward the main checkout behind the user's back
|
|
671
795
|
// (both are the same directory when the session IS the main checkout).
|
|
672
|
-
const outcome = await updateBranch(deps.exec, facts.toplevel);
|
|
796
|
+
const outcome = await updateBranch(deps.exec, facts.toplevel, run);
|
|
673
797
|
const result = { branch: outcome.branch, updated: outcome.updated };
|
|
674
798
|
return { status: 200, body: result };
|
|
675
799
|
}
|
|
676
800
|
catch (error) {
|
|
801
|
+
if (error instanceof CancelledError)
|
|
802
|
+
return fail(499, error.message);
|
|
677
803
|
if (error instanceof GitError)
|
|
678
804
|
return gitFailure(error);
|
|
679
805
|
return fail(500, error instanceof Error ? error.message : String(error));
|
|
680
806
|
}
|
|
807
|
+
finally {
|
|
808
|
+
end();
|
|
809
|
+
}
|
|
681
810
|
}
|
|
682
811
|
/**
|
|
683
812
|
* POST /inspect — pre-delete facts for one worktree directory: the
|
package/lib/stream.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamed route responses: the HTTP half of the live fetch/update progress.
|
|
3
|
+
*
|
|
4
|
+
* A streamed route answers `200` at once and then writes one JSON
|
|
5
|
+
* {@link SyncFrame} per line while the handler works; the last line is `done`
|
|
6
|
+
* and carries the status and body the same route would have answered in one
|
|
7
|
+
* piece. The status line is therefore no longer the verdict — the `done`
|
|
8
|
+
* frame is — which is what lets a failure that happens after minutes of
|
|
9
|
+
* transfer still be reported.
|
|
10
|
+
*
|
|
11
|
+
* The caller cancels by closing the connection. A response that is not yet
|
|
12
|
+
* finished when its socket closes aborts the handler's signal, which kills
|
|
13
|
+
* git. (`res`'s `close`, not `req`'s: a request body that was fully read
|
|
14
|
+
* closes early on modern Node whether or not the client is still there.)
|
|
15
|
+
*
|
|
16
|
+
* @module git-worktree/stream
|
|
17
|
+
*/
|
|
18
|
+
import type { RouteLive, RouteOutcome } from './routes.js';
|
|
19
|
+
/** The slice of `http.ServerResponse` a stream needs — a fake in tests. */
|
|
20
|
+
export interface StreamTarget {
|
|
21
|
+
writeHead: (status: number, headers: Record<string, string>) => unknown;
|
|
22
|
+
write: (chunk: string) => unknown;
|
|
23
|
+
end: () => unknown;
|
|
24
|
+
on: (event: 'close', listener: () => void) => unknown;
|
|
25
|
+
readonly writableEnded: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run one handler as an NDJSON stream.
|
|
29
|
+
* @param res - the response to stream into.
|
|
30
|
+
* @param handle - the route logic; emits events through `live` and resolves
|
|
31
|
+
* with the outcome that becomes the `done` frame.
|
|
32
|
+
*/
|
|
33
|
+
export declare function streamRoute(res: StreamTarget, handle: (live: RouteLive) => Promise<RouteOutcome>): Promise<void>;
|
package/lib/stream.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamed route responses: the HTTP half of the live fetch/update progress.
|
|
3
|
+
*
|
|
4
|
+
* A streamed route answers `200` at once and then writes one JSON
|
|
5
|
+
* {@link SyncFrame} per line while the handler works; the last line is `done`
|
|
6
|
+
* and carries the status and body the same route would have answered in one
|
|
7
|
+
* piece. The status line is therefore no longer the verdict — the `done`
|
|
8
|
+
* frame is — which is what lets a failure that happens after minutes of
|
|
9
|
+
* transfer still be reported.
|
|
10
|
+
*
|
|
11
|
+
* The caller cancels by closing the connection. A response that is not yet
|
|
12
|
+
* finished when its socket closes aborts the handler's signal, which kills
|
|
13
|
+
* git. (`res`'s `close`, not `req`'s: a request body that was fully read
|
|
14
|
+
* closes early on modern Node whether or not the client is still there.)
|
|
15
|
+
*
|
|
16
|
+
* @module git-worktree/stream
|
|
17
|
+
*/
|
|
18
|
+
import { NDJSON_TYPE } from './wire.js';
|
|
19
|
+
/**
|
|
20
|
+
* Run one handler as an NDJSON stream.
|
|
21
|
+
* @param res - the response to stream into.
|
|
22
|
+
* @param handle - the route logic; emits events through `live` and resolves
|
|
23
|
+
* with the outcome that becomes the `done` frame.
|
|
24
|
+
*/
|
|
25
|
+
export async function streamRoute(res, handle) {
|
|
26
|
+
const controller = new AbortController();
|
|
27
|
+
res.on('close', () => {
|
|
28
|
+
if (!res.writableEnded)
|
|
29
|
+
controller.abort();
|
|
30
|
+
});
|
|
31
|
+
res.writeHead(200, {
|
|
32
|
+
'content-type': `${NDJSON_TYPE}; charset=utf-8`,
|
|
33
|
+
'cache-control': 'no-store',
|
|
34
|
+
// Tell a reverse proxy not to hold the lines back until the stream ends.
|
|
35
|
+
'x-accel-buffering': 'no',
|
|
36
|
+
});
|
|
37
|
+
const write = (frame) => {
|
|
38
|
+
// Nobody is listening after an abort; writing would only raise EPIPE.
|
|
39
|
+
if (controller.signal.aborted || res.writableEnded)
|
|
40
|
+
return;
|
|
41
|
+
res.write(`${JSON.stringify(frame)}\n`);
|
|
42
|
+
};
|
|
43
|
+
let outcome;
|
|
44
|
+
try {
|
|
45
|
+
outcome = await handle({ signal: controller.signal, emit: write });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
// Handlers answer their own failures; this is the backstop for a bug.
|
|
49
|
+
outcome = { status: 500, body: { error: error instanceof Error ? error.message : String(error) } };
|
|
50
|
+
}
|
|
51
|
+
write({ type: 'done', status: outcome.status, body: outcome.body });
|
|
52
|
+
if (!res.writableEnded)
|
|
53
|
+
res.end();
|
|
54
|
+
}
|
package/lib/wire.d.ts
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
export declare const ROUTE_PREFIX = "/plugin/git-worktree";
|
|
9
9
|
/** GET ROUTE_PREFIX/status?path=<absolute dir> */
|
|
10
10
|
export declare const ROUTE_STATUS = "/plugin/git-worktree/status";
|
|
11
|
+
/** GET ROUTE_PREFIX/head?path=<absolute dir> — checked-out branch only.
|
|
12
|
+
* A file read of HEAD, not a git process. */
|
|
13
|
+
export declare const ROUTE_HEAD = "/plugin/git-worktree/head";
|
|
11
14
|
/** POST ROUTE_PREFIX/worktree — create-or-reuse a worktree for a branch. */
|
|
12
15
|
export declare const ROUTE_WORKTREE = "/plugin/git-worktree/worktree";
|
|
13
16
|
/** POST ROUTE_PREFIX/switch — in-place branch switch of the main checkout. */
|
|
@@ -21,10 +24,21 @@ export declare const ROUTE_BRANCH_RENAME = "/plugin/git-worktree/branch-rename";
|
|
|
21
24
|
/** POST ROUTE_PREFIX/branch-delete — delete a LOCAL branch (`-d`, merged
|
|
22
25
|
* only; git refuses the rest). */
|
|
23
26
|
export declare const ROUTE_BRANCH_DELETE = "/plugin/git-worktree/branch-delete";
|
|
24
|
-
/** POST ROUTE_PREFIX/fetch — sync remote-tracking refs (fetch every remote + prune).
|
|
27
|
+
/** POST ROUTE_PREFIX/fetch — sync remote-tracking refs (fetch every remote + prune).
|
|
28
|
+
* Streams {@link SyncFrame} lines (NDJSON) so a long transfer can show progress. */
|
|
25
29
|
export declare const ROUTE_FETCH = "/plugin/git-worktree/fetch";
|
|
26
|
-
/** POST ROUTE_PREFIX/update — fast-forward the current branch to its upstream.
|
|
30
|
+
/** POST ROUTE_PREFIX/update — fast-forward the current branch to its upstream.
|
|
31
|
+
* Streams {@link SyncFrame} lines (NDJSON), like {@link ROUTE_FETCH}. */
|
|
27
32
|
export declare const ROUTE_UPDATE = "/plugin/git-worktree/update";
|
|
33
|
+
/** POST push-plan — resolve the selected branch's push destination. */
|
|
34
|
+
export declare const ROUTE_PUSH_PLAN = "/plugin/git-worktree/push-plan";
|
|
35
|
+
/** POST push-preview — inspect one explicit destination without pushing. */
|
|
36
|
+
export declare const ROUTE_PUSH_PREVIEW = "/plugin/git-worktree/push-preview";
|
|
37
|
+
/** POST push — push one explicit local branch. Streams {@link SyncFrame}
|
|
38
|
+
* lines (NDJSON), like {@link ROUTE_FETCH}; the `done` body is a
|
|
39
|
+
* {@link PushResult}. A cancel (499) kills `git push`; the remote only moves
|
|
40
|
+
* a ref once the whole pack has arrived, so a stopped transfer changes nothing. */
|
|
41
|
+
export declare const ROUTE_PUSH = "/plugin/git-worktree/push";
|
|
28
42
|
/** POST ROUTE_PREFIX/group — git belonging facts for a batch of workspace paths. */
|
|
29
43
|
export declare const ROUTE_GROUP = "/plugin/git-worktree/group";
|
|
30
44
|
/** POST ROUTE_PREFIX/inspect — pre-delete facts for one worktree directory. */
|
|
@@ -51,6 +65,59 @@ export interface BranchEntry {
|
|
|
51
65
|
ahead?: number;
|
|
52
66
|
/** Commits the local branch is BEHIND its upstream (same conditions). */
|
|
53
67
|
behind?: number;
|
|
68
|
+
/** Configured upstream; absent means unpublished, not synchronized. */
|
|
69
|
+
upstream?: string;
|
|
70
|
+
/** The configured upstream no longer exists in the local tracking refs. */
|
|
71
|
+
upstreamGone?: true;
|
|
72
|
+
}
|
|
73
|
+
export interface PushPlanBody {
|
|
74
|
+
repoPath: string;
|
|
75
|
+
branch: string;
|
|
76
|
+
}
|
|
77
|
+
export interface PushPlan {
|
|
78
|
+
branch: string;
|
|
79
|
+
remotes: string[];
|
|
80
|
+
remote: string;
|
|
81
|
+
target: string;
|
|
82
|
+
/** Publishing or changing the tracking destination requires a target dialog. */
|
|
83
|
+
confirm: boolean;
|
|
84
|
+
upstream?: string;
|
|
85
|
+
/** `/push-plan` only: display-only snapshot of the default destination from
|
|
86
|
+
* local refs, so opening the push window needs one request, not two. Absent
|
|
87
|
+
* when it could not be built; never a substitute for the verified preview. */
|
|
88
|
+
local?: PushPreview;
|
|
89
|
+
}
|
|
90
|
+
export interface PushBody extends PushPlanBody {
|
|
91
|
+
/** Both present only after the user confirms the publish destination. */
|
|
92
|
+
remote?: string;
|
|
93
|
+
target?: string;
|
|
94
|
+
tags?: 'none' | 'all' | 'follow';
|
|
95
|
+
/** Force only the destination branch, leased against the previewed OID. */
|
|
96
|
+
force?: boolean;
|
|
97
|
+
/** Empty string means the remote branch did not exist in the preview. */
|
|
98
|
+
expectedTarget?: string;
|
|
99
|
+
sourceOid?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface PushPreviewBody extends PushPlanBody {
|
|
102
|
+
remote: string;
|
|
103
|
+
target: string;
|
|
104
|
+
/** Approximate display-only preview from local tracking refs; never contacts the remote. */
|
|
105
|
+
localOnly?: boolean;
|
|
106
|
+
}
|
|
107
|
+
export interface PushPreview {
|
|
108
|
+
sourceOid: string;
|
|
109
|
+
targetOid: string | null;
|
|
110
|
+
commits: {
|
|
111
|
+
oid: string;
|
|
112
|
+
subject: string;
|
|
113
|
+
}[];
|
|
114
|
+
total: number;
|
|
115
|
+
truncated: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface PushResult {
|
|
118
|
+
branch: string;
|
|
119
|
+
remote: string;
|
|
120
|
+
target: string;
|
|
54
121
|
}
|
|
55
122
|
/** One existing worktree of the repository. */
|
|
56
123
|
export interface WorktreeEntry {
|
|
@@ -85,6 +152,22 @@ export type RepoStatus = {
|
|
|
85
152
|
/** Resolved worktree storage root (absolute) — what the settings say today. */
|
|
86
153
|
rootDir: string;
|
|
87
154
|
};
|
|
155
|
+
/**
|
|
156
|
+
* Response of GET head. `repo: false` — the directory is not inside a
|
|
157
|
+
* repository. `pending` — a repository was found but HEAD could not be read
|
|
158
|
+
* completely this tick (mid-checkout, partial write); callers skip the tick
|
|
159
|
+
* rather than guess a name. `currentBranch` is the branch, or `HEAD` when
|
|
160
|
+
* detached.
|
|
161
|
+
*/
|
|
162
|
+
export type HeadStatus = {
|
|
163
|
+
repo: false;
|
|
164
|
+
} | {
|
|
165
|
+
repo: true;
|
|
166
|
+
pending: true;
|
|
167
|
+
} | {
|
|
168
|
+
repo: true;
|
|
169
|
+
currentBranch: string;
|
|
170
|
+
};
|
|
88
171
|
/** POST worktree request body. */
|
|
89
172
|
export interface CreateWorktreeBody {
|
|
90
173
|
/** Any directory inside the repository (workspace cwd). */
|
|
@@ -209,6 +292,35 @@ export interface UpdateResult {
|
|
|
209
292
|
/** False when the upstream already contained the branch (nothing moved). */
|
|
210
293
|
updated: boolean;
|
|
211
294
|
}
|
|
295
|
+
/** Content type of a streamed route: one JSON {@link SyncFrame} per line. */
|
|
296
|
+
export declare const NDJSON_TYPE = "application/x-ndjson";
|
|
297
|
+
/**
|
|
298
|
+
* A live event of a long route while it still runs.
|
|
299
|
+
* - `progress` is git's own progress line (`Receiving objects: 3% (2147/58680),
|
|
300
|
+
* 708.01 KiB | 128.00 KiB/s`) with its percentage when it has one, and the
|
|
301
|
+
* remote being fetched (the host fetches them one by one and names each
|
|
302
|
+
* ahead of its counter lines);
|
|
303
|
+
* - `merge` marks the switch from fetching to the fast-forward, the one step
|
|
304
|
+
* that can no longer be cancelled.
|
|
305
|
+
*/
|
|
306
|
+
export type SyncEvent = {
|
|
307
|
+
type: 'progress';
|
|
308
|
+
text: string;
|
|
309
|
+
percent?: number;
|
|
310
|
+
remote?: string;
|
|
311
|
+
} | {
|
|
312
|
+
type: 'merge';
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* One line of a streamed route response. The last line is always `done`,
|
|
316
|
+
* carrying the status and body the same route would have answered in one piece
|
|
317
|
+
* (the result, or a {@link RouteError}); a stream that ends without it was cut.
|
|
318
|
+
*/
|
|
319
|
+
export type SyncFrame = SyncEvent | {
|
|
320
|
+
type: 'done';
|
|
321
|
+
status: number;
|
|
322
|
+
body: unknown;
|
|
323
|
+
};
|
|
212
324
|
/** Error envelope every non-2xx response carries. */
|
|
213
325
|
export interface RouteError {
|
|
214
326
|
error: string;
|
package/lib/wire.js
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
export const ROUTE_PREFIX = '/plugin/git-worktree';
|
|
9
9
|
/** GET ROUTE_PREFIX/status?path=<absolute dir> */
|
|
10
10
|
export const ROUTE_STATUS = `${ROUTE_PREFIX}/status`;
|
|
11
|
+
/** GET ROUTE_PREFIX/head?path=<absolute dir> — checked-out branch only.
|
|
12
|
+
* A file read of HEAD, not a git process. */
|
|
13
|
+
export const ROUTE_HEAD = `${ROUTE_PREFIX}/head`;
|
|
11
14
|
/** POST ROUTE_PREFIX/worktree — create-or-reuse a worktree for a branch. */
|
|
12
15
|
export const ROUTE_WORKTREE = `${ROUTE_PREFIX}/worktree`;
|
|
13
16
|
/** POST ROUTE_PREFIX/switch — in-place branch switch of the main checkout. */
|
|
@@ -21,10 +24,21 @@ export const ROUTE_BRANCH_RENAME = `${ROUTE_PREFIX}/branch-rename`;
|
|
|
21
24
|
/** POST ROUTE_PREFIX/branch-delete — delete a LOCAL branch (`-d`, merged
|
|
22
25
|
* only; git refuses the rest). */
|
|
23
26
|
export const ROUTE_BRANCH_DELETE = `${ROUTE_PREFIX}/branch-delete`;
|
|
24
|
-
/** POST ROUTE_PREFIX/fetch — sync remote-tracking refs (fetch every remote + prune).
|
|
27
|
+
/** POST ROUTE_PREFIX/fetch — sync remote-tracking refs (fetch every remote + prune).
|
|
28
|
+
* Streams {@link SyncFrame} lines (NDJSON) so a long transfer can show progress. */
|
|
25
29
|
export const ROUTE_FETCH = `${ROUTE_PREFIX}/fetch`;
|
|
26
|
-
/** POST ROUTE_PREFIX/update — fast-forward the current branch to its upstream.
|
|
30
|
+
/** POST ROUTE_PREFIX/update — fast-forward the current branch to its upstream.
|
|
31
|
+
* Streams {@link SyncFrame} lines (NDJSON), like {@link ROUTE_FETCH}. */
|
|
27
32
|
export const ROUTE_UPDATE = `${ROUTE_PREFIX}/update`;
|
|
33
|
+
/** POST push-plan — resolve the selected branch's push destination. */
|
|
34
|
+
export const ROUTE_PUSH_PLAN = `${ROUTE_PREFIX}/push-plan`;
|
|
35
|
+
/** POST push-preview — inspect one explicit destination without pushing. */
|
|
36
|
+
export const ROUTE_PUSH_PREVIEW = `${ROUTE_PREFIX}/push-preview`;
|
|
37
|
+
/** POST push — push one explicit local branch. Streams {@link SyncFrame}
|
|
38
|
+
* lines (NDJSON), like {@link ROUTE_FETCH}; the `done` body is a
|
|
39
|
+
* {@link PushResult}. A cancel (499) kills `git push`; the remote only moves
|
|
40
|
+
* a ref once the whole pack has arrived, so a stopped transfer changes nothing. */
|
|
41
|
+
export const ROUTE_PUSH = `${ROUTE_PREFIX}/push`;
|
|
28
42
|
/** POST ROUTE_PREFIX/group — git belonging facts for a batch of workspace paths. */
|
|
29
43
|
export const ROUTE_GROUP = `${ROUTE_PREFIX}/group`;
|
|
30
44
|
/** POST ROUTE_PREFIX/inspect — pre-delete facts for one worktree directory. */
|
|
@@ -41,3 +55,5 @@ export const ROUTE_WORKTREES_ALL = `${ROUTE_PREFIX}/worktrees-all`;
|
|
|
41
55
|
/** POST ROUTE_PREFIX/purge — delete a NON-git directory sitting DIRECTLY in
|
|
42
56
|
* the storage root (an orphaned leftover whose .git is already gone). */
|
|
43
57
|
export const ROUTE_PURGE = `${ROUTE_PREFIX}/purge`;
|
|
58
|
+
/** Content type of a streamed route: one JSON {@link SyncFrame} per line. */
|
|
59
|
+
export const NDJSON_TYPE = 'application/x-ndjson';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laoyuehanni/dsh-git-worktree",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "DSH plugin: branch visibility and git worktree isolation for Web UI sessions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -65,6 +65,15 @@
|
|
|
65
65
|
]
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "tsc -p tsconfig.json",
|
|
70
|
+
"build:client": "tsdown",
|
|
71
|
+
"build:all": "pnpm run build && pnpm run build:client",
|
|
72
|
+
"watch:client": "tsdown --watch",
|
|
73
|
+
"test": "vitest run",
|
|
74
|
+
"typecheck": "tsc -p tsconfig.client.json --noEmit",
|
|
75
|
+
"prepublishOnly": "pnpm run typecheck && pnpm test && pnpm run build:all"
|
|
76
|
+
},
|
|
68
77
|
"peerDependencies": {
|
|
69
78
|
"@deepseek-ai/cordis": "^4.0.4",
|
|
70
79
|
"@deepseek-ai/dsh-host-webserver": "^0.2.0-rc.1",
|
|
@@ -129,12 +138,5 @@
|
|
|
129
138
|
"engines": {
|
|
130
139
|
"node": ">=22.19"
|
|
131
140
|
},
|
|
132
|
-
"
|
|
133
|
-
|
|
134
|
-
"build:client": "tsdown",
|
|
135
|
-
"build:all": "pnpm run build && pnpm run build:client",
|
|
136
|
-
"watch:client": "tsdown --watch",
|
|
137
|
-
"test": "vitest run",
|
|
138
|
-
"typecheck": "tsc -p tsconfig.client.json --noEmit"
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
+
"packageManager": "pnpm@11.8.0"
|
|
142
|
+
}
|