dsh-git-branch-manage 1.0.5 → 1.0.6
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/lib/client.js +853 -194
- package/lib/git.d.ts +39 -1
- package/lib/git.js +47 -2
- package/lib/index.js +3 -2
- package/lib/routes.d.ts +18 -3
- package/lib/routes.js +78 -4
- package/lib/wire.d.ts +31 -0
- package/lib/wire.js +2 -0
- package/package.json +1 -1
package/lib/git.d.ts
CHANGED
|
@@ -182,6 +182,28 @@ export declare function switchBranch(exec: Exec, checkoutDir: string, branch: st
|
|
|
182
182
|
* start point with `checkout` false).
|
|
183
183
|
*/
|
|
184
184
|
export declare function createBranch(exec: Exec, cwd: string, name: string, from?: string, checkout?: boolean): Promise<string>;
|
|
185
|
+
/** Outcome of {@link createTag}: the tag created and the commit it points at. */
|
|
186
|
+
export interface TagOutcome {
|
|
187
|
+
tag: string;
|
|
188
|
+
hash: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Create a tag at an existing commit (`git tag`). Tags are repository-wide
|
|
192
|
+
* refs, so the command runs at the repository root.
|
|
193
|
+
*
|
|
194
|
+
* A message makes it an ANNOTATED tag (`-a -m`) — the only shape that carries
|
|
195
|
+
* an author and date, and what `git describe` prefers; without one the tag is
|
|
196
|
+
* lightweight and is just an alias for the commit. Both are created locally
|
|
197
|
+
* only: pushing a tag is a deliberate, separate publish step that this panel
|
|
198
|
+
* does not perform on a menu click.
|
|
199
|
+
* @param exec - executor seam.
|
|
200
|
+
* @param repoRoot - main worktree directory.
|
|
201
|
+
* @param name - tag name (git validates; failures raise GitError).
|
|
202
|
+
* @param target - commit to tag; absent tags the repository's current HEAD.
|
|
203
|
+
* @param message - optional annotation message; non-empty = annotated tag.
|
|
204
|
+
* @returns the tag name and the commit hash it points at.
|
|
205
|
+
*/
|
|
206
|
+
export declare function createTag(exec: Exec, repoRoot: string, name: string, target?: string, message?: string): Promise<TagOutcome>;
|
|
185
207
|
/**
|
|
186
208
|
* Rename a LOCAL branch (`git branch -m`): branch refs are repository-wide,
|
|
187
209
|
* so the command runs at the repository root and every worktree HEAD pointing
|
|
@@ -447,18 +469,34 @@ export interface CommitEntryRaw {
|
|
|
447
469
|
body: string;
|
|
448
470
|
refs: string[];
|
|
449
471
|
}
|
|
472
|
+
/** The extra log filters the history card's toolbar drives. */
|
|
473
|
+
export interface LogFilter {
|
|
474
|
+
/** Every ref (local + remote branches, tags) instead of the checkout's
|
|
475
|
+
* HEAD — the history card's default view. Ignored when `ref` is given. */
|
|
476
|
+
all?: boolean;
|
|
477
|
+
/** Committer-author substring/regex, forwarded as `--author=<value>`. */
|
|
478
|
+
author?: string;
|
|
479
|
+
/** Lower/upper bound on the commit date, epoch milliseconds. */
|
|
480
|
+
since?: number;
|
|
481
|
+
until?: number;
|
|
482
|
+
}
|
|
450
483
|
/**
|
|
451
484
|
* Paginated history of the queried checkout. `ref` is verified with
|
|
452
485
|
* `rev-parse --verify` first, so an arbitrary string can never reach the log
|
|
453
486
|
* arguments as anything but a resolvable rev. An unborn checkout (no commits
|
|
454
487
|
* yet) answers an empty page instead of an error.
|
|
488
|
+
*
|
|
489
|
+
* `--topo-order` is unconditional: the history card draws lane lines from
|
|
490
|
+
* `parents`, and a pure date order would interleave a branch's commits
|
|
491
|
+
* before their merge base, leaving edges pointing at rows not yet painted.
|
|
455
492
|
* @param exec - executor seam.
|
|
456
493
|
* @param cwd - the checkout directory.
|
|
457
494
|
* @param limit - page size (1..200, validated upstream).
|
|
458
495
|
* @param skip - offset (>= 0, validated upstream).
|
|
459
496
|
* @param ref - optional starting rev; absent = the checkout's HEAD.
|
|
497
|
+
* @param filter - optional all-refs/author/date window.
|
|
460
498
|
*/
|
|
461
|
-
export declare function logHistory(exec: Exec, cwd: string, limit: number, skip: number, ref?: string): Promise<CommitEntryRaw[]>;
|
|
499
|
+
export declare function logHistory(exec: Exec, cwd: string, limit: number, skip: number, ref?: string, filter?: LogFilter): Promise<CommitEntryRaw[]>;
|
|
462
500
|
/** One file row of {@link commitFiles}. */
|
|
463
501
|
export interface CommitFileRow {
|
|
464
502
|
path: string;
|
package/lib/git.js
CHANGED
|
@@ -433,6 +433,35 @@ export async function createBranch(exec, cwd, name, from, checkout = false) {
|
|
|
433
433
|
await git(exec, cwd, ['branch', name, from]);
|
|
434
434
|
return name;
|
|
435
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* Create a tag at an existing commit (`git tag`). Tags are repository-wide
|
|
438
|
+
* refs, so the command runs at the repository root.
|
|
439
|
+
*
|
|
440
|
+
* A message makes it an ANNOTATED tag (`-a -m`) — the only shape that carries
|
|
441
|
+
* an author and date, and what `git describe` prefers; without one the tag is
|
|
442
|
+
* lightweight and is just an alias for the commit. Both are created locally
|
|
443
|
+
* only: pushing a tag is a deliberate, separate publish step that this panel
|
|
444
|
+
* does not perform on a menu click.
|
|
445
|
+
* @param exec - executor seam.
|
|
446
|
+
* @param repoRoot - main worktree directory.
|
|
447
|
+
* @param name - tag name (git validates; failures raise GitError).
|
|
448
|
+
* @param target - commit to tag; absent tags the repository's current HEAD.
|
|
449
|
+
* @param message - optional annotation message; non-empty = annotated tag.
|
|
450
|
+
* @returns the tag name and the commit hash it points at.
|
|
451
|
+
*/
|
|
452
|
+
export async function createTag(exec, repoRoot, name, target, message) {
|
|
453
|
+
const text = message?.trim() ?? '';
|
|
454
|
+
const args = ['tag'];
|
|
455
|
+
if (text !== '')
|
|
456
|
+
args.push('-a', name, '-m', text);
|
|
457
|
+
else
|
|
458
|
+
args.push(name);
|
|
459
|
+
if (target !== undefined && target !== '')
|
|
460
|
+
args.push(target);
|
|
461
|
+
await git(exec, repoRoot, args);
|
|
462
|
+
const hash = (await git(exec, repoRoot, ['rev-list', '-n', '1', name])).trim();
|
|
463
|
+
return { tag: name, hash };
|
|
464
|
+
}
|
|
436
465
|
/**
|
|
437
466
|
* Rename a LOCAL branch (`git branch -m`): branch refs are repository-wide,
|
|
438
467
|
* so the command runs at the repository root and every worktree HEAD pointing
|
|
@@ -879,13 +908,18 @@ export function parseLogOutput(out) {
|
|
|
879
908
|
* `rev-parse --verify` first, so an arbitrary string can never reach the log
|
|
880
909
|
* arguments as anything but a resolvable rev. An unborn checkout (no commits
|
|
881
910
|
* yet) answers an empty page instead of an error.
|
|
911
|
+
*
|
|
912
|
+
* `--topo-order` is unconditional: the history card draws lane lines from
|
|
913
|
+
* `parents`, and a pure date order would interleave a branch's commits
|
|
914
|
+
* before their merge base, leaving edges pointing at rows not yet painted.
|
|
882
915
|
* @param exec - executor seam.
|
|
883
916
|
* @param cwd - the checkout directory.
|
|
884
917
|
* @param limit - page size (1..200, validated upstream).
|
|
885
918
|
* @param skip - offset (>= 0, validated upstream).
|
|
886
919
|
* @param ref - optional starting rev; absent = the checkout's HEAD.
|
|
920
|
+
* @param filter - optional all-refs/author/date window.
|
|
887
921
|
*/
|
|
888
|
-
export async function logHistory(exec, cwd, limit, skip, ref) {
|
|
922
|
+
export async function logHistory(exec, cwd, limit, skip, ref, filter) {
|
|
889
923
|
let start;
|
|
890
924
|
if (ref !== undefined && ref !== '' && ref !== 'HEAD') {
|
|
891
925
|
const verified = await gitMaybe(exec, cwd, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
|
|
@@ -894,10 +928,21 @@ export async function logHistory(exec, cwd, limit, skip, ref) {
|
|
|
894
928
|
}
|
|
895
929
|
start = verified.trim();
|
|
896
930
|
}
|
|
931
|
+
// A ref narrows the walk to that ref's ancestry; `--all` is only the
|
|
932
|
+
// no-ref default. Combining them would list every branch under a
|
|
933
|
+
// "this branch" filter.
|
|
934
|
+
const all = filter?.all === true && start === undefined;
|
|
935
|
+
const author = filter?.author?.trim() ?? '';
|
|
936
|
+
const since = filter?.since;
|
|
937
|
+
const until = filter?.until;
|
|
897
938
|
try {
|
|
898
939
|
const out = await git(exec, cwd, [
|
|
899
|
-
'log', `--max-count=${String(limit)}`, `--skip=${String(skip)}`,
|
|
940
|
+
'log', `--max-count=${String(limit)}`, `--skip=${String(skip)}`, '--topo-order',
|
|
900
941
|
'--date=iso-strict', `--pretty=format:${LOG_FORMAT}`,
|
|
942
|
+
...(all ? ['--all'] : []),
|
|
943
|
+
...(author === '' ? [] : [`--author=${author}`]),
|
|
944
|
+
...(since === undefined ? [] : [`--since=${new Date(since).toISOString()}`]),
|
|
945
|
+
...(until === undefined ? [] : [`--until=${new Date(until).toISOString()}`]),
|
|
901
946
|
...(start === undefined ? [] : [start]),
|
|
902
947
|
]);
|
|
903
948
|
return parseLogOutput(out);
|
package/lib/index.js
CHANGED
|
@@ -9,9 +9,9 @@ import { homedir } from 'node:os';
|
|
|
9
9
|
import z from '@deepseek-ai/schemastery';
|
|
10
10
|
import { childProcessExec } from './git.js';
|
|
11
11
|
import { ACCEL_DEFAULT_URL, accelerateUrlError } from './normalize.js';
|
|
12
|
-
import { handleAiCommitMessage, handleChanges, handleCommit, handleCommitFiles, handleCreateBranch, handleCreateWorktree, handleDeleteBranch, handleEnsureDirectory, handleFetch, handleGroupWorktrees, handleInspectWorktree, handleLog, handlePathExists, handlePurgeDirectory, handleRemoveWorktree, handleRenameBranch, handleStage, handleStatus, handleSwitch, handleUpdate, handlePush, handleWorktreesAll, } from './routes.js';
|
|
12
|
+
import { handleAiCommitMessage, handleChanges, handleCommit, handleCommitFiles, handleCreateBranch, handleCreateTag, handleCreateWorktree, handleDeleteBranch, handleEnsureDirectory, handleFetch, handleGroupWorktrees, handleInspectWorktree, handleLog, handlePathExists, handlePurgeDirectory, handleRemoveWorktree, handleRenameBranch, handleStage, handleStatus, handleSwitch, handleUpdate, handlePush, handleWorktreesAll, } from './routes.js';
|
|
13
13
|
import { validateRootDir } from './settings.js';
|
|
14
|
-
import { ROUTE_AI_COMMIT_MESSAGE, ROUTE_BRANCH, ROUTE_BRANCH_DELETE, ROUTE_BRANCH_RENAME, ROUTE_CHANGES, ROUTE_COMMIT, ROUTE_COMMIT_FILES, ROUTE_ENSURE_DIRECTORY, ROUTE_EXISTS, ROUTE_FETCH, ROUTE_GROUP, ROUTE_INSPECT, ROUTE_LOG, ROUTE_PUSH, ROUTE_PURGE, ROUTE_REMOVE, ROUTE_STAGE, ROUTE_STATUS, ROUTE_SWITCH, ROUTE_UPDATE, ROUTE_WORKTREE, ROUTE_WORKTREES_ALL } from './wire.js';
|
|
14
|
+
import { ROUTE_AI_COMMIT_MESSAGE, ROUTE_BRANCH, ROUTE_BRANCH_DELETE, ROUTE_BRANCH_RENAME, ROUTE_CHANGES, ROUTE_COMMIT, ROUTE_COMMIT_FILES, ROUTE_ENSURE_DIRECTORY, ROUTE_EXISTS, ROUTE_FETCH, ROUTE_GROUP, ROUTE_INSPECT, ROUTE_LOG, ROUTE_PUSH, ROUTE_PURGE, ROUTE_REMOVE, ROUTE_STAGE, ROUTE_STATUS, ROUTE_SWITCH, ROUTE_TAG, ROUTE_UPDATE, ROUTE_WORKTREE, ROUTE_WORKTREES_ALL } from './wire.js';
|
|
15
15
|
export const name = 'dsh-git-branch';
|
|
16
16
|
export const inject = [];
|
|
17
17
|
/** Largest accepted request body (bytes) — these payloads are a few strings. */
|
|
@@ -227,6 +227,7 @@ export function apply(ctx, config = {}) {
|
|
|
227
227
|
postRoute(ROUTE_COMMIT, 'commit', handleCommit);
|
|
228
228
|
postRoute(ROUTE_LOG, 'log', handleLog);
|
|
229
229
|
postRoute(ROUTE_COMMIT_FILES, 'commit-files', handleCommitFiles);
|
|
230
|
+
postRoute(ROUTE_TAG, 'tag', handleCreateTag);
|
|
230
231
|
// The AI commit-message route exists only where the host tree provides
|
|
231
232
|
// the dsh-llm service: the injection resolves once the service is up and
|
|
232
233
|
// never fires without it, so an llm-less deployment answers 404 and the
|
package/lib/routes.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type CopyFilesSeams } from './copy-files.js';
|
|
6
6
|
import { type DirExists, type ExcludeSeams, type Exec } from './git.js';
|
|
7
|
-
import type { AiCommitMessageResult, ChangesResult, CommitFilesResult, CommitResult, CreateBranchResult, CreateWorktreeResult, EnsureDirectoryResult, FetchResult, GroupWorkspacesResult, InspectWorktreeResult, LogResult, PathExistsResult, PurgeDirectoryResult, RemoveWorktreeResult, RepoStatus, RouteError, StageResult, SwitchResult, UpdateResult, WorktreesAllResult } from './wire.js';
|
|
7
|
+
import type { AiCommitMessageResult, ChangesResult, CommitFilesResult, CommitResult, CreateBranchResult, CreateTagResult, CreateWorktreeResult, EnsureDirectoryResult, FetchResult, GroupWorkspacesResult, InspectWorktreeResult, LogResult, PathExistsResult, PurgeDirectoryResult, RemoveWorktreeResult, RepoStatus, RouteError, StageResult, SwitchResult, UpdateResult, WorktreesAllResult } from './wire.js';
|
|
8
8
|
/** Everything the handlers need from the host half. */
|
|
9
9
|
export interface RouteDeps {
|
|
10
10
|
exec: Exec;
|
|
@@ -50,7 +50,7 @@ export declare function fsMkdirRecursive(path: string): Promise<void>;
|
|
|
50
50
|
/** One route outcome: HTTP status plus the JSON body. */
|
|
51
51
|
export interface RouteOutcome {
|
|
52
52
|
status: number;
|
|
53
|
-
body: RepoStatus | CreateWorktreeResult | SwitchResult | CreateBranchResult | FetchResult | UpdateResult | GroupWorkspacesResult | InspectWorktreeResult | RemoveWorktreeResult | PathExistsResult | EnsureDirectoryResult | WorktreesAllResult | PurgeDirectoryResult | ChangesResult | StageResult | CommitResult | LogResult | CommitFilesResult | AiCommitMessageResult | RouteError;
|
|
53
|
+
body: RepoStatus | CreateWorktreeResult | SwitchResult | CreateBranchResult | FetchResult | UpdateResult | GroupWorkspacesResult | InspectWorktreeResult | RemoveWorktreeResult | PathExistsResult | EnsureDirectoryResult | WorktreesAllResult | PurgeDirectoryResult | ChangesResult | StageResult | CommitResult | LogResult | CommitFilesResult | CreateTagResult | AiCommitMessageResult | RouteError;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* POST /group — git belonging facts for a batch of workspace directories.
|
|
@@ -274,10 +274,25 @@ export declare const LOG_LIMIT_MAX = 200;
|
|
|
274
274
|
* POST /log — one page of the queried checkout's history. The optional `ref`
|
|
275
275
|
* is verified server-side (`rev-parse --verify`), an unborn checkout answers
|
|
276
276
|
* an empty page, and everything else surfaces git's own stderr.
|
|
277
|
+
*
|
|
278
|
+
* `all` walks every ref instead of HEAD (the history card's default view: one
|
|
279
|
+
* graph holding all branches, tags, and their merge edges). `author` and the
|
|
280
|
+
* `since`/`until` window are pushed down to git rather than filtered in the
|
|
281
|
+
* browser — the card paginates, so a client-side filter would only narrow the
|
|
282
|
+
* page it already has and silently hide matches on later pages.
|
|
277
283
|
* @param deps - host dependencies.
|
|
278
|
-
* @param body - parsed request body: `{ repoPath, limit?, skip?, ref? }`.
|
|
284
|
+
* @param body - parsed request body: `{ repoPath, limit?, skip?, ref?, all?, author?, since?, until? }`.
|
|
279
285
|
*/
|
|
280
286
|
export declare function handleLog(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
|
|
287
|
+
/**
|
|
288
|
+
* POST /tag — create a tag at an existing commit of the queried repository.
|
|
289
|
+
* The target is restricted to a commit hash (the only shape the history card
|
|
290
|
+
* sends), so an arbitrary string can never reach `git tag` as a flag; git
|
|
291
|
+
* validates the tag name itself and a duplicate surfaces as 400.
|
|
292
|
+
* @param deps - host dependencies.
|
|
293
|
+
* @param body - parsed request body: `{ repoPath, name, target?, message? }`.
|
|
294
|
+
*/
|
|
295
|
+
export declare function handleCreateTag(deps: RouteDeps, body: unknown): Promise<RouteOutcome>;
|
|
281
296
|
/**
|
|
282
297
|
* POST /commit-files — the files one commit of the queried checkout changed.
|
|
283
298
|
* The hash is verified server-side; unknown revisions answer 400.
|
package/lib/routes.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
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, collectAiDiff, commitFiles, commitIndex, createBranch, cutoutBranchName, deleteBranch, fetchAll, fsDirExists, inspectWorktree, isAbsoluteDir, isStageablePath, logHistory, probeRepo, probeWorkspaceGit, removeWorktree, renameBranch, resolveBranch, pushBranch, stagePaths, switchBranch, updateBranch, workingChanges } from './git.js';
|
|
8
|
+
import { appendWorktreeExclude, fsExcludeSeams, GitError, addWorktree, addWorktreeCutout, collectAiDiff, commitFiles, commitIndex, createBranch, createTag, cutoutBranchName, deleteBranch, fetchAll, fsDirExists, inspectWorktree, isAbsoluteDir, isStageablePath, logHistory, probeRepo, probeWorkspaceGit, removeWorktree, renameBranch, resolveBranch, pushBranch, stagePaths, switchBranch, updateBranch, workingChanges } from './git.js';
|
|
9
9
|
import { ACCEL_DEFAULT_URL, accelerateUrlError, isAbsoluteConfigPath, normalizeAccelerateUrl, sanitizeBranchDir } from './normalize.js';
|
|
10
10
|
import { resolveRootDir } from './settings.js';
|
|
11
11
|
import { COMMIT_MESSAGE_LIMIT } from './wire.js';
|
|
@@ -1006,15 +1006,24 @@ export async function handleCommit(deps, body) {
|
|
|
1006
1006
|
/** Default and maximum page size of POST /log. */
|
|
1007
1007
|
export const LOG_LIMIT_DEFAULT = 50;
|
|
1008
1008
|
export const LOG_LIMIT_MAX = 200;
|
|
1009
|
+
/** Bound for the author filter and the tag annotation (characters). */
|
|
1010
|
+
const LOG_AUTHOR_LIMIT = 200;
|
|
1011
|
+
const TAG_MESSAGE_LIMIT = 5000;
|
|
1009
1012
|
/**
|
|
1010
1013
|
* POST /log — one page of the queried checkout's history. The optional `ref`
|
|
1011
1014
|
* is verified server-side (`rev-parse --verify`), an unborn checkout answers
|
|
1012
1015
|
* an empty page, and everything else surfaces git's own stderr.
|
|
1016
|
+
*
|
|
1017
|
+
* `all` walks every ref instead of HEAD (the history card's default view: one
|
|
1018
|
+
* graph holding all branches, tags, and their merge edges). `author` and the
|
|
1019
|
+
* `since`/`until` window are pushed down to git rather than filtered in the
|
|
1020
|
+
* browser — the card paginates, so a client-side filter would only narrow the
|
|
1021
|
+
* page it already has and silently hide matches on later pages.
|
|
1013
1022
|
* @param deps - host dependencies.
|
|
1014
|
-
* @param body - parsed request body: `{ repoPath, limit?, skip?, ref? }`.
|
|
1023
|
+
* @param body - parsed request body: `{ repoPath, limit?, skip?, ref?, all?, author?, since?, until? }`.
|
|
1015
1024
|
*/
|
|
1016
1025
|
export async function handleLog(deps, body) {
|
|
1017
|
-
const parsed = readBody(body, ['repoPath'], [], ['ref'], ['limit', 'skip']);
|
|
1026
|
+
const parsed = readBody(body, ['repoPath'], ['all'], ['ref', 'author'], ['limit', 'skip', 'since', 'until']);
|
|
1018
1027
|
if (isOutcome(parsed))
|
|
1019
1028
|
return parsed;
|
|
1020
1029
|
const repoPath = readRepoPath(parsed);
|
|
@@ -1031,14 +1040,79 @@ export async function handleLog(deps, body) {
|
|
|
1031
1040
|
if (ref !== undefined && (ref.trim() === '' || ref.length > 300 || ref.startsWith('-'))) {
|
|
1032
1041
|
return fail(400, '"ref" must be a non-empty revision name');
|
|
1033
1042
|
}
|
|
1043
|
+
const author = parsed.author;
|
|
1044
|
+
if (author !== undefined && (author.trim() === '' || author.length > LOG_AUTHOR_LIMIT)) {
|
|
1045
|
+
return fail(400, `"author" must be a non-empty string of at most ${String(LOG_AUTHOR_LIMIT)} characters`);
|
|
1046
|
+
}
|
|
1047
|
+
const since = parsed.since;
|
|
1048
|
+
const until = parsed.until;
|
|
1049
|
+
for (const [key, value] of [['since', since], ['until', until]]) {
|
|
1050
|
+
if (value !== undefined && (!Number.isFinite(value) || value <= 0)) {
|
|
1051
|
+
return fail(400, `"${key}" must be a positive epoch-millisecond timestamp`);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
if (since !== undefined && until !== undefined && until < since) {
|
|
1055
|
+
return fail(400, '"until" must not be earlier than "since"');
|
|
1056
|
+
}
|
|
1034
1057
|
try {
|
|
1035
|
-
const commits = await logHistory(deps.exec, repoPath, limit, skip, ref
|
|
1058
|
+
const commits = await logHistory(deps.exec, repoPath, limit, skip, ref, {
|
|
1059
|
+
all: parsed.all === true,
|
|
1060
|
+
...(author === undefined ? {} : { author }),
|
|
1061
|
+
...(since === undefined ? {} : { since }),
|
|
1062
|
+
...(until === undefined ? {} : { until }),
|
|
1063
|
+
});
|
|
1036
1064
|
return { status: 200, body: { commits } };
|
|
1037
1065
|
}
|
|
1038
1066
|
catch (error) {
|
|
1039
1067
|
return checkoutFailure(error);
|
|
1040
1068
|
}
|
|
1041
1069
|
}
|
|
1070
|
+
/**
|
|
1071
|
+
* POST /tag — create a tag at an existing commit of the queried repository.
|
|
1072
|
+
* The target is restricted to a commit hash (the only shape the history card
|
|
1073
|
+
* sends), so an arbitrary string can never reach `git tag` as a flag; git
|
|
1074
|
+
* validates the tag name itself and a duplicate surfaces as 400.
|
|
1075
|
+
* @param deps - host dependencies.
|
|
1076
|
+
* @param body - parsed request body: `{ repoPath, name, target?, message? }`.
|
|
1077
|
+
*/
|
|
1078
|
+
export async function handleCreateTag(deps, body) {
|
|
1079
|
+
const parsed = readBody(body, ['repoPath', 'name'], [], ['target', 'message']);
|
|
1080
|
+
if (isOutcome(parsed))
|
|
1081
|
+
return parsed;
|
|
1082
|
+
const { repoPath, name, target, message } = parsed;
|
|
1083
|
+
if (!isAbsoluteDir(repoPath))
|
|
1084
|
+
return fail(400, '"repoPath" must be an absolute directory');
|
|
1085
|
+
if (name.trim() === '')
|
|
1086
|
+
return fail(400, '"name" must be non-empty');
|
|
1087
|
+
// A leading dash would ride `git tag` as a flag — reject before the exec.
|
|
1088
|
+
if (name.startsWith('-'))
|
|
1089
|
+
return fail(400, '"name" must not start with "-"');
|
|
1090
|
+
if (name.length > 300)
|
|
1091
|
+
return fail(400, '"name" must be at most 300 characters');
|
|
1092
|
+
// The target lands on `git tag <name> <target>` verbatim: restrict it to the
|
|
1093
|
+
// object id shape the history card sends rather than trusting a free string.
|
|
1094
|
+
if (target !== undefined && !/^[0-9a-fA-F]{4,64}$/.test(target)) {
|
|
1095
|
+
return fail(400, '"target" must be a git object id');
|
|
1096
|
+
}
|
|
1097
|
+
if (message !== undefined && message.length > TAG_MESSAGE_LIMIT) {
|
|
1098
|
+
return fail(400, `"message" must be at most ${String(TAG_MESSAGE_LIMIT)} characters`);
|
|
1099
|
+
}
|
|
1100
|
+
try {
|
|
1101
|
+
const facts = await probeRepo(deps.exec, repoPath, deps.dirExists);
|
|
1102
|
+
if (facts === undefined)
|
|
1103
|
+
return fail(400, `"${repoPath}" is not inside a git repository`);
|
|
1104
|
+
// Tag refs are repository-wide metadata and touch no checkout, so the
|
|
1105
|
+
// command runs at the repository root — the same scope as a branch rename.
|
|
1106
|
+
const result = await createTag(deps.exec, facts.repoRoot, name, target, message);
|
|
1107
|
+
const body = result;
|
|
1108
|
+
return { status: 200, body };
|
|
1109
|
+
}
|
|
1110
|
+
catch (error) {
|
|
1111
|
+
if (error instanceof GitError)
|
|
1112
|
+
return gitFailure(error);
|
|
1113
|
+
return fail(500, error instanceof Error ? error.message : String(error));
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1042
1116
|
/**
|
|
1043
1117
|
* POST /commit-files — the files one commit of the queried checkout changed.
|
|
1044
1118
|
* The hash is verified server-side; unknown revisions answer 400.
|
package/lib/wire.d.ts
CHANGED
|
@@ -53,6 +53,8 @@ export declare const ROUTE_COMMIT = "/plugin/git-worktree/commit";
|
|
|
53
53
|
export declare const ROUTE_LOG = "/plugin/git-worktree/log";
|
|
54
54
|
/** POST ROUTE_PREFIX/commit-files — the files one commit changed. */
|
|
55
55
|
export declare const ROUTE_COMMIT_FILES = "/plugin/git-worktree/commit-files";
|
|
56
|
+
/** POST ROUTE_PREFIX/tag — create a tag at an existing commit. */
|
|
57
|
+
export declare const ROUTE_TAG = "/plugin/git-worktree/tag";
|
|
56
58
|
/** POST ROUTE_PREFIX/ai-commit-message — one-shot LLM commit message from
|
|
57
59
|
* the staged diff (mounted only where the host provides the llm service). */
|
|
58
60
|
export declare const ROUTE_AI_COMMIT_MESSAGE = "/plugin/git-worktree/ai-commit-message";
|
|
@@ -472,11 +474,40 @@ export interface LogBody {
|
|
|
472
474
|
skip?: number;
|
|
473
475
|
/** Optional starting ref (a branch name, `HEAD`, …); validated server-side. */
|
|
474
476
|
ref?: string;
|
|
477
|
+
/** Walk every ref (branches + tags) instead of the checkout's HEAD — the
|
|
478
|
+
* history card's default view, which is what makes branches/merges visible.
|
|
479
|
+
* Ignored when `ref` is given. */
|
|
480
|
+
all?: boolean;
|
|
481
|
+
/** Committer-author substring/regex (`--author`); absent = every author. */
|
|
482
|
+
author?: string;
|
|
483
|
+
/** Lower bound on the commit date, epoch milliseconds (`--since`). */
|
|
484
|
+
since?: number;
|
|
485
|
+
/** Upper bound on the commit date, epoch milliseconds (`--until`). */
|
|
486
|
+
until?: number;
|
|
475
487
|
}
|
|
476
488
|
/** POST log response body. */
|
|
477
489
|
export interface LogResult {
|
|
478
490
|
commits: CommitEntry[];
|
|
479
491
|
}
|
|
492
|
+
/** POST tag request body. */
|
|
493
|
+
export interface CreateTagBody {
|
|
494
|
+
/** Any directory inside the repository (tag refs are repository-wide). */
|
|
495
|
+
repoPath: string;
|
|
496
|
+
/** User-typed tag name, verbatim (git validates it). */
|
|
497
|
+
name: string;
|
|
498
|
+
/** The commit to tag (a full or abbreviated hash, validated server-side);
|
|
499
|
+
* absent tags the repository's current HEAD. */
|
|
500
|
+
target?: string;
|
|
501
|
+
/** Optional annotation message; non-empty creates an ANNOTATED tag. */
|
|
502
|
+
message?: string;
|
|
503
|
+
}
|
|
504
|
+
/** POST tag response body. */
|
|
505
|
+
export interface CreateTagResult {
|
|
506
|
+
/** The tag created. */
|
|
507
|
+
tag: string;
|
|
508
|
+
/** The commit hash the tag points at. */
|
|
509
|
+
hash: string;
|
|
510
|
+
}
|
|
480
511
|
/** One file row of POST commit-files. */
|
|
481
512
|
export interface CommitFileEntry {
|
|
482
513
|
/** New path, relative to the repository root. */
|
package/lib/wire.js
CHANGED
|
@@ -53,6 +53,8 @@ export const ROUTE_COMMIT = `${ROUTE_PREFIX}/commit`;
|
|
|
53
53
|
export const ROUTE_LOG = `${ROUTE_PREFIX}/log`;
|
|
54
54
|
/** POST ROUTE_PREFIX/commit-files — the files one commit changed. */
|
|
55
55
|
export const ROUTE_COMMIT_FILES = `${ROUTE_PREFIX}/commit-files`;
|
|
56
|
+
/** POST ROUTE_PREFIX/tag — create a tag at an existing commit. */
|
|
57
|
+
export const ROUTE_TAG = `${ROUTE_PREFIX}/tag`;
|
|
56
58
|
/** POST ROUTE_PREFIX/ai-commit-message — one-shot LLM commit message from
|
|
57
59
|
* the staged diff (mounted only where the host provides the llm service). */
|
|
58
60
|
export const ROUTE_AI_COMMIT_MESSAGE = `${ROUTE_PREFIX}/ai-commit-message`;
|
package/package.json
CHANGED