@laoyuehanni/dsh-git-worktree 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # dsh-git-worktree
2
2
 
3
+ [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
4
+
3
5
  ![dsh-git-worktree in the Web UI](gitworktree.png)
4
6
 
5
7
  [简体中文](./README.zh.md) | English
@@ -10,22 +12,40 @@ A dsh plugin for simple branch & worktree management in the Web UI. The composer
10
12
 
11
13
  Repo: <https://github.com/LaoYueHanNi/dsh-git-worktree>
12
14
 
15
+ > [!IMPORTANT]
16
+ > **Upgrading from a GitHub install of 0.3.2 or earlier?** Since 0.4.0 the plugin is distributed on npm as `@laoyuehanni/dsh-git-worktree` (the unscoped name was already taken on the registry). A legacy `github:` install **cannot be upgraded with `update`** — the package was renamed, and an in-place update leaves the plugin failing to load. From 0.4.0 on, remove the old package name first, then install again:
17
+ >
18
+ > ```sh
19
+ > dsh plugin --profile web remove dsh-git-worktree
20
+ > dsh plugin --profile web add @laoyuehanni/dsh-git-worktree
21
+ > ```
22
+ >
23
+ > Worktree folders under `~/.dsh/gitworktree/` and the plugin's settings are untouched by the migration — everything carries over.
24
+
13
25
  ## Features
14
26
 
15
- - **IDEA-style branch picker**: the branch menu treats `/` as a folder hierarchy — collapsible folders, last-segment labels, the checked-out branch's chain opens by default and is centered on open. Single click selects a row; double-click or Enter opens the right-side confirm flyout. The left tool strip offers **locate current branch** and **expand/collapse all**; the bottom search keeps the matching branches' ancestor folders and highlights the hit substring. Clipped labels expose the full name on hover.
16
- - **Branch switching**: pick a branch from the chip's menu and confirm — an in-place `git switch`. Inside a linked worktree it switches within that worktree only.
17
- - **Worktree isolation**: on a blank session, checking the **Worktree** toggle pops the cutout confirm right above the chip — confirming it cuts a NEW branch (`<current>-wt`, `-wt2`, … past taken names) out of the current checkout into a fresh isolated worktree; the chip's branch picker stays available for picking another branch, which turns the pick into `git worktree add` under `~/.dsh/gitworktree/<repo>-<branch>/`. Either way the folder registers as a real workspace with a fresh blank session. Same-branch re-picks reuse the existing worktree; stale registrations recover via `git worktree prune`. Dismissing the confirm and sending the message anyway knowingly stays in the current directory.
27
+ - **IDEA-style branch picker**: the branch menu treats `/` as a folder hierarchy — collapsible folders, last-segment labels, the checked-out branch's chain opens by default and is centered on open. The list renders in two collapsible groups, **local branches** and **remote branches**; under a single remote the remote group strips its `<remote>/` prefix, with several remotes the full names stay (`origin`/`upstream` become the folder layer). Single click selects a row; double-click or Enter opens the right-side confirm flyout. The left tool strip offers **locate current branch** and **expand/collapse all**; the bottom search keeps the matching branches' ancestor folders and highlights the hit substring. Clipped labels expose the full name on hover. Local branches with an upstream trail **↑N/↓N divergence marks** (hover for the full meaning).
28
+ - **Remote branch checkout**: pick `origin/feat-x` in the remote group and confirm — it checks out in place with a tracking local branch `feat-x` created by git's dwim; with the worktree toggle on, the pick creates the twin branch isolated in its own worktree instead.
29
+ - **Worktree quick hop**: the main checkout's blank-session branch menu collects the branches held by live worktrees into a「工作树」(Worktrees) group (hover shows the directory path) — **double-click hops the session straight into that directory** and starts a fresh session there. No git action, no confirm; the group hides once a session has started.
30
+ - **Branch switching**: pick a branch from the chip's menu and confirm — an in-place `git switch`. Inside a **linked worktree** the whole entry scopes down: a blank session still lists every branch (dimmed), but any branch action (worktree hops and in-place creation included) answers with a hint to start from the main checkout — and the worktree toggle doesn't render there; a started session's menu shows nothing but its own branch (fetch and update-current still work — neither moves the checkout).
31
+ - **In-place branch creation**: the branch menu's toolbar plus opens a create flyout right of the card — type the name there (validated as you type against git's ref-name rules plus a duplicate check; an illegal or already-taken name shows an inline error) and press Create: the NEW branch is cut from the session directory's current checkout and checked out in place in one stroke (`git switch -c`), detached HEAD included. A failure toasts and keeps the flyout open for a renamed retry — the worktree-less sibling of the cutout flow.
32
+ - **Remote sync**: the branch menu's last toolbar tool fetches every remote and prunes stale tracking branches (`git fetch --all --prune`) — remote-side additions and deletions show up in the list the moment it lands, no terminal round-trip. The menu stays open and refreshes in place; a failure toasts.
33
+ - **Branch update**: the solid arrow next to the dashed one updates the CURRENT branch — fetch every remote, then fast-forward it to its upstream (`--ff-only`). A diverged branch, a missing upstream, or conflicting uncommitted changes are refused with git's own explanation; the plugin never stashes or rewrites history on your behalf.
34
+ - **Worktree isolation**: on a blank session, checking the **Worktree** toggle pops the cutout dialog right above the chip — the new branch's name is editable there (pre-filled with the first free `<current>-wt`, suffixing past taken names), and confirming cuts it out of the current checkout into a fresh isolated worktree; the chip's branch picker stays available for picking another branch, which turns the pick into `git worktree add` under `~/.dsh/gitworktree/<repo>-<branch>/`. Either way the folder registers as a real workspace with a fresh blank session. Same-branch re-picks reuse the existing worktree; stale registrations recover via `git worktree prune`. Dismissing the confirm and sending the message anyway knowingly stays in the current directory.
18
35
  - **Storage root configurable**: the **Git Worktree** card under **Settings → Plugins** — a native folder picker or a typed absolute path, effective on save (new worktrees land in the new location; existing ones stay put and remain listable/reusable by git). Empty selects the default `$DSH_HOME/gitworktree` (`~/.dsh/gitworktree`). The value lives in the shared dsh settings document; a legacy `~/.dsh/git-worktree/settings.json` value migrates into it automatically on upgrade (the old file is renamed `.migrated` and kept).
36
+ - **Sidebar workspace grouping**: because DSH has no multi-workspace grouping API, the plugin replaces the native sidebar 1:1 and clusters same-repository workspaces (main checkout plus worktrees) under a collapsible **repository group**. The main row reads `Main (branch)`, worktree rows read their branch, grouping is derived from on-disk git facts (nothing extra is stored), and a repository without worktrees stays a single native-looking row. The card's **Group workspaces** switch (experimental, default on) restores the native list instantly.
37
+
38
+ ![Same-repository workspaces grouped in the sidebar](sidebar-grouping.png)
19
39
 
20
40
  ## Install
21
41
 
22
- ### From GitHub (recommended)
42
+ ### From npm
23
43
 
24
44
  ```sh
25
- dsh plugin --profile web add github:LaoYueHanNi/dsh-git-worktree
45
+ dsh plugin --profile web add @laoyuehanni/dsh-git-worktree
26
46
  ```
27
47
 
28
- > The package declares `dsh.bundle`, so `add` wires the plugin into the profile's layer stack automatically — no config editing needed. The built `lib/` ships in the repo (there is no `prepare` script), so git installs work out of the box without any build allowlist. Requires the `web` profile (`dsh web`).
48
+ > The package declares `dsh.bundle`, so `add` wires the plugin into the profile's layer stack automatically — no config editing needed. The compiled `lib/` ships in the npm tarball, so installs work out of the box without any build step. Requires the `web` profile (`dsh web`).
29
49
 
30
50
  ### From a local directory (development)
31
51
 
@@ -38,13 +58,13 @@ dsh plugin --profile web add link:D:/Code/dsh-worktree
38
58
  ## Update
39
59
 
40
60
  ```sh
41
- dsh plugin --profile web update dsh-git-worktree
61
+ dsh plugin --profile web update @laoyuehanni/dsh-git-worktree
42
62
  ```
43
63
 
44
64
  ## Remove
45
65
 
46
66
  ```sh
47
- dsh plugin --profile web remove dsh-git-worktree
67
+ dsh plugin --profile web remove @laoyuehanni/dsh-git-worktree
48
68
  ```
49
69
 
50
70
  The plugin is removed from the profile and stops loading. Worktree folders under `~/.dsh/gitworktree/` are kept; the migrated legacy settings file (`settings.json.migrated`) can be deleted manually if unwanted — the plugin's own settings live in the dsh settings document.
@@ -60,7 +80,7 @@ npm test # vitest (60 tests)
60
80
  node scripts/smoke.mjs # real-git smoke over the built lib
61
81
  ```
62
82
 
63
- > **No `prepare` script — by design.** The compiled `lib/` output is committed to the repo. pnpm ≥ 10 refuses to run build scripts of git-hosted dependencies unless they are allowlisted (`ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`), so a `prepare` script would break the zero-config `github:` install for every user. Shipping prebuilt output instead keeps `dsh plugin add github:LaoYueHanNi/dsh-git-worktree` working out of the box. **After changing anything under `src/`, always rebuild and commit the updated `lib/`**, or installs will get stale output:
83
+ > **No `prepare` script — by design.** The compiled `lib/` output is committed to the repo and ships in the npm tarball. pnpm ≥ 10 refuses to run dependency build scripts unless they are allowlisted, so a `prepare` script would surface as a skipped or failed install step for pnpm users. Shipping prebuilt output instead keeps `dsh plugin add @laoyuehanni/dsh-git-worktree` working out of the box. **After changing anything under `src/`, always rebuild and commit the updated `lib/`** (and release a new version), or installs will get stale output:
64
84
 
65
85
  ```sh
66
86
  npm run build && npm run build:client
package/README.zh.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # dsh-git-worktree
2
2
 
3
- ![Web 界面中的 dsh-git-worktree](gitworktree.png)
3
+ [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
4
+
5
+ ![Web 界面中的 dsh-git-worktree](gitworktree_zh.png)
4
6
 
5
7
  简体中文 | [English](./README.md)
6
8
 
@@ -10,22 +12,40 @@
10
12
 
11
13
  仓库:<https://github.com/LaoYueHanNi/dsh-git-worktree>
12
14
 
15
+ > [!IMPORTANT]
16
+ > **从 0.3.2 及更早的 GitHub 直装升级?** 0.4.0 起插件发布到 npm,包名变更为 `@laoyuehanni/dsh-git-worktree`(原裸名在 npm 上已被第三方占用)。旧的 `github:` 安装**无法通过 `update` 升级**——包名已变,原地 update 会导致插件加载失败。从 0.4.0 开始使用,需先移除旧包名,再重新安装:
17
+ >
18
+ > ```sh
19
+ > dsh plugin --profile web remove dsh-git-worktree
20
+ > dsh plugin --profile web add @laoyuehanni/dsh-git-worktree
21
+ > ```
22
+ >
23
+ > 迁移不影响数据:`~/.dsh/gitworktree/` 下的 worktree 目录与插件设置完整保留。
24
+
13
25
  ## 功能
14
26
 
15
- - **IDEA 风格分支选择器**:分支菜单把 `/` 视为文件夹层级 —— 可折叠文件夹、末段标签,当前分支所在链路默认展开并居中。单击选中(蓝底),双击或 Enter 弹出右侧确认弹层。左侧工具栏提供**定位当前分支**与**全部展开/折叠**;底部搜索保留匹配分支的祖先文件夹并高亮命中字符;超长标签悬停显示全名。
16
- - **分支切换**:从 chip 菜单选分支、确认后原地 `git switch`。在 worktree 会话内只作用于该 worktree。
17
- - **工作树隔离**:空白会话上勾选**「工作树」**立即在 chip 上方弹出「从当前分支切出」确认弹窗——确认后从当前检出切出**新分支**(`<当前分支>-wt`,重名自动递增 `-wt2`、`-wt3`…)并隔离到全新 worktree;分支 chip 的菜单仍可打开,选其他分支则在 `~/.dsh/gitworktree/<仓库>-<分支>/` 下执行 `git worktree add`。两条路径都会注册为真实工作区并跳转到新目录的空白会话。重复选同一分支直接复用;失效注册自动 prune 恢复。取消确认弹窗后直接发消息,即默许在当前目录开始会话。
27
+ - **IDEA 风格分支选择器**:分支菜单把 `/` 视为文件夹层级 —— 可折叠文件夹、末段标签,当前分支所在链路默认展开并居中。列表分**本地分支**与**远程分支**两个可折叠分组;远程组在单远程仓库下自动剥掉 `<远程>/` 前缀,多远程则保留全名(`origin`/`upstream` 成为组内文件夹)。单击选中(蓝底),双击或 Enter 弹出右侧确认弹层。左侧工具栏提供**定位当前分支**与**全部展开/折叠**;底部搜索保留匹配分支的祖先文件夹并高亮命中字符;超长标签悬停显示全名。有上游的本地分支行尾显示 **↑N/↓N 领先落后标记**(悬停看完整含义)。
28
+ - **远程分支检出**:远程组里选中 `origin/feat-x`,确认后原地检出并自动创建跟踪本地分支 `feat-x`(git dwim);勾选工作树模式则从远程分支新建孪生分支并隔离进独立 worktree。
29
+ - **工作树快捷入口**:主仓库空白会话的分支菜单把被 worktree 占用的分支收进「工作树」分组(hover 显示目录路径),**双击直接跳进对应目录**开始新会话——零 git 动作、无确认弹层;已开始的会话不显示该分组。
30
+ - **分支切换**:从 chip 菜单选分支、确认后原地 `git switch`。**worktree 会话的入口整体收敛**:未启动时其他分支照常展示但置灰,任何分支操作(含工作树跳转、新建分支)都会提示「分支操作请在主仓库发起」,工作树开关也不渲染——发起 worktree / 新分支是主仓库的决策;已启动时菜单仅展示该会话自己的分支(提取、更新当前分支仍可用,两者不动检出)。
31
+ - **原地新建分支**:分支菜单左侧工具栏的加号在卡片右侧弹出创建弹窗——弹窗内输入名称(边输边校验 git ref-name 规则 + 重名检查,非法或重名时输入框下方标红提示),点「确认」一把完成新建并原地切换(`git switch -c`),detached HEAD 亦可用;失败 toast 后弹窗保留、可改名重试——即不带工作树的「切出」孪生流程。
32
+ - **远程同步**:分支菜单工具栏末位的刷新按钮执行 `git fetch --all --prune`——远程新增/删除的分支当场出现在列表里,无需去终端;菜单保持打开并原地刷新,失败 toast。
33
+ - **更新当前分支**:实线箭头(虚线提取旁)更新**当前分支**——先 fetch 全部远程,再把当前分支快进(`--ff-only`)到其上游。本地分叉、无上游、工作区改动冲突都会被拒绝并给出 git 原话;插件绝不代你 stash 或改写历史。
34
+ - **工作树隔离**:空白会话上勾选**「工作树」**立即在 chip 上方弹出「从当前分支切出」确认弹窗——弹窗内可**编辑新分支名**(预填第一个空闲的 `<当前分支>-wt`,重名自动递增 `-wt2`、`-wt3`…),确认后从当前检出切出**新分支**并隔离到全新 worktree;分支 chip 的菜单仍可打开,选其他分支则在 `~/.dsh/gitworktree/<仓库>-<分支>/` 下执行 `git worktree add`。两条路径都会注册为真实工作区并跳转到新目录的空白会话。重复选同一分支直接复用;失效注册自动 prune 恢复。取消确认弹窗后直接发消息,即默许在当前目录开始会话。
18
35
  - **存放根路径可配**:**设置 → 插件**页签下的 **Git 工作树** 卡片 —— 原生目录选择器或手输绝对路径,保存即生效(新建的 worktree 落在新目录,已有的留在原地,git 仍能识别复用)。留空使用默认 `$DSH_HOME/gitworktree`(`~/.dsh/gitworktree`)。设置存于 dsh 统一设置文档;旧版 `~/.dsh/git-work-tree/settings.json` 的已保存值会在升级后自动迁入(原文件改名 `.migrated` 保留)。
36
+ - **聚合工作区**:DSH 尚未开放多工作区聚合接口,故按原生侧边栏 1:1 替换左侧列表,并把同一仓库的主仓库与 worktree 工作区聚成可折叠的**仓库组**——主行显示 `主仓库(分支)`,工作树行显示分支。分组从磁盘 git 事实派生、不存关系数据;没有 worktree 的仓库保持单行。设置卡 **聚合工作区**(测试功能,默认开)可随时切回原生。
37
+
38
+ ![侧边栏按仓库聚合工作区](sidebar-grouping_zh.png)
19
39
 
20
40
  ## 安装
21
41
 
22
- ### 从 GitHub 安装(推荐)
42
+ ### 从 npm 安装
23
43
 
24
44
  ```sh
25
- dsh plugin --profile web add github:LaoYueHanNi/dsh-git-worktree
45
+ dsh plugin --profile web add @laoyuehanni/dsh-git-worktree
26
46
  ```
27
47
 
28
- > 包声明了 `dsh.bundle`,`add` 会自动把插件挂进 profile 的层栈,无需手动改配置。构建产物 `lib/` 随仓库提交(没有 `prepare` 脚本),git 安装开箱即用,无需任何构建白名单。需要 `web` profile(`dsh web`)。
48
+ > 包声明了 `dsh.bundle`,`add` 会自动把插件挂进 profile 的层栈,无需手动改配置。编译产物 `lib/` 随 npm 包分发,安装开箱即用,无需任何构建步骤。需要 `web` profile(`dsh web`)。
29
49
 
30
50
  ### 从本地目录安装(开发调试用)
31
51
 
@@ -38,13 +58,13 @@ dsh plugin --profile web add link:D:/Code/dsh-worktree
38
58
  ## 更新
39
59
 
40
60
  ```sh
41
- dsh plugin --profile web update dsh-git-worktree
61
+ dsh plugin --profile web update @laoyuehanni/dsh-git-worktree
42
62
  ```
43
63
 
44
64
  ## 移除
45
65
 
46
66
  ```sh
47
- dsh plugin --profile web remove dsh-git-worktree
67
+ dsh plugin --profile web remove @laoyuehanni/dsh-git-worktree
48
68
  ```
49
69
 
50
70
  插件会从 profile 移除并停止加载。`~/.dsh/gitworktree/` 下的 worktree 目录会保留;已迁移的旧设置文件(`settings.json.migrated`)如不需要可手动删除,插件自身的设置项存于 dsh 设置文档。
@@ -60,7 +80,7 @@ npm test # vitest(60 项测试)
60
80
  node scripts/smoke.mjs # 基于构建产物的真实 git 冒烟
61
81
  ```
62
82
 
63
- > **刻意不设 `prepare` 脚本。** 编译产物 `lib/` 已提交进仓库。pnpm ≥ 10 默认拒绝执行 git-hosted 依赖的构建脚本,除非加入白名单(报错 `ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`),因此若保留 `prepare`,每个用户用 `github:` 安装都会失败。改为随仓库分发预构建产物后,`dsh plugin add github:LaoYueHanNi/dsh-git-worktree` 才能零配置开箱即用。**改动 `src/` 下的任何文件后,务必重新构建并提交更新后的 `lib/`**,否则别人安装到的是旧产物:
83
+ > **刻意不设 `prepare` 脚本。** 编译产物 `lib/` 已提交进仓库,并随 npm 包分发。pnpm ≥ 10 默认拒绝执行依赖的构建脚本,除非加入白名单,因此若保留 `prepare`,pnpm 用户的安装会出现被跳过或失败的步骤。改为分发预构建产物后,`dsh plugin add @laoyuehanni/dsh-git-worktree` 才能开箱即用。**改动 `src/` 下的任何文件后,务必重新构建并提交更新后的 `lib/`**(并发布新版本),否则别人安装到的是旧产物:
64
84
 
65
85
  ```sh
66
86
  npm run build && npm run build:client