dsh-git-branch-manage 1.0.4 → 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/routes.js CHANGED
@@ -5,8 +5,8 @@
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';
9
- import { isAbsoluteConfigPath, sanitizeBranchDir } from './normalize.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
+ 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';
12
12
  /** Real fs-backed one-level directory listing (names only). Plain FILES are
@@ -39,6 +39,18 @@ export async function fsMkdirRecursive(path) {
39
39
  function fail(status, error) {
40
40
  return { status, body: { error } };
41
41
  }
42
+ /**
43
+ * The rewrite prefix for one request's network READ commands: the cn-accelerate
44
+ * mirror prefix when the switch is on and the URL setting is usable (the
45
+ * shipped default fills an absent URL), else undefined — no injection and the
46
+ * direct connection runs unchanged. PUSH never consults this helper.
47
+ */
48
+ function accelPrefix(deps) {
49
+ if (deps.sectionCnAccelerate?.() !== true)
50
+ return undefined;
51
+ const url = deps.sectionCnAccelerateUrl?.() ?? ACCEL_DEFAULT_URL;
52
+ return accelerateUrlError(url) === undefined ? normalizeAccelerateUrl(url) : undefined;
53
+ }
42
54
  /** Upper bound on distinct paths one /group request may probe. */
43
55
  const GROUP_PATHS_LIMIT = 256;
44
56
  /** Probes per in-flight batch — polite on Windows, where each git call is a
@@ -414,7 +426,7 @@ export async function handleCreateWorktree(deps, body) {
414
426
  const resolved = await resolveBranch(deps.exec, facts.repoRoot, branch);
415
427
  if (resolved?.remote !== undefined) {
416
428
  try {
417
- await fetchAll(deps.exec, facts.repoRoot);
429
+ await fetchAll(deps.exec, facts.repoRoot, accelPrefix(deps));
418
430
  }
419
431
  catch (error) {
420
432
  fetchWarning = error instanceof GitError ? error.stderr.trim() : error instanceof Error ? error.message : String(error);
@@ -649,7 +661,7 @@ export async function handleFetch(deps, body) {
649
661
  const facts = await probeRepo(deps.exec, repoPath, deps.dirExists);
650
662
  if (facts === undefined)
651
663
  return fail(400, `"${repoPath}" is not inside a git repository`);
652
- await fetchAll(deps.exec, facts.repoRoot);
664
+ await fetchAll(deps.exec, facts.repoRoot, accelPrefix(deps));
653
665
  const result = { remote: 'all' };
654
666
  return { status: 200, body: result };
655
667
  }
@@ -682,7 +694,7 @@ export async function handleUpdate(deps, body) {
682
694
  // session "update current branch" means the branch that worktree holds.
683
695
  // `repoRoot` would fast-forward the main checkout behind the user's back
684
696
  // (both are the same directory when the session IS the main checkout).
685
- const outcome = await updateBranch(deps.exec, facts.toplevel);
697
+ const outcome = await updateBranch(deps.exec, facts.toplevel, accelPrefix(deps));
686
698
  const result = { branch: outcome.branch, updated: outcome.updated };
687
699
  return { status: 200, body: result };
688
700
  }
@@ -994,15 +1006,24 @@ export async function handleCommit(deps, body) {
994
1006
  /** Default and maximum page size of POST /log. */
995
1007
  export const LOG_LIMIT_DEFAULT = 50;
996
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;
997
1012
  /**
998
1013
  * POST /log — one page of the queried checkout's history. The optional `ref`
999
1014
  * is verified server-side (`rev-parse --verify`), an unborn checkout answers
1000
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.
1001
1022
  * @param deps - host dependencies.
1002
- * @param body - parsed request body: `{ repoPath, limit?, skip?, ref? }`.
1023
+ * @param body - parsed request body: `{ repoPath, limit?, skip?, ref?, all?, author?, since?, until? }`.
1003
1024
  */
1004
1025
  export async function handleLog(deps, body) {
1005
- const parsed = readBody(body, ['repoPath'], [], ['ref'], ['limit', 'skip']);
1026
+ const parsed = readBody(body, ['repoPath'], ['all'], ['ref', 'author'], ['limit', 'skip', 'since', 'until']);
1006
1027
  if (isOutcome(parsed))
1007
1028
  return parsed;
1008
1029
  const repoPath = readRepoPath(parsed);
@@ -1019,14 +1040,79 @@ export async function handleLog(deps, body) {
1019
1040
  if (ref !== undefined && (ref.trim() === '' || ref.length > 300 || ref.startsWith('-'))) {
1020
1041
  return fail(400, '"ref" must be a non-empty revision name');
1021
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
+ }
1022
1057
  try {
1023
- 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
+ });
1024
1064
  return { status: 200, body: { commits } };
1025
1065
  }
1026
1066
  catch (error) {
1027
1067
  return checkoutFailure(error);
1028
1068
  }
1029
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
+ }
1030
1116
  /**
1031
1117
  * POST /commit-files — the files one commit of the queried checkout changed.
1032
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-git-branch-manage",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "提供 git 分支与 worktree 管理:输入框工具栏显示当前分支、可原地切换;支持 IDEA 风格分支选择器、远程分支检出、右键操作菜单(新建/重命名/删除/复制)、推送与更新当前分支,以及把分支隔离到独立 worktree 工作区,并管理其创建与删除。",
5
5
  "keywords": [
6
6
  "dsh",