Skip to content

Commit 6cfc4e7

Browse files
authored
feat(treeView): show last commit time on worktree items (#51)
* feat(treeView): show last commit time on worktree items Adds a $LAST_COMMIT token to treeView.worktreeDescriptionTemplate that renders the worktree's last commit as a relative timestamp (e.g. "3 weeks ago"), making it easy to spot stale worktrees from the tree view. The full ISO timestamp is also surfaced in the hover tooltip. * Address tooltip date string, address missing l10n missing translations
1 parent b5c0097 commit 6cfc4e7

13 files changed

Lines changed: 44 additions & 5 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ Customize Git Worktree Manager to fit your workflow:
8888
- **`git-worktree-manager.treeView.toSCM`**
8989
Display worktrees in the Source Control view.
9090

91+
- **`git-worktree-manager.treeView.worktreeDescriptionTemplate`**
92+
Customize the description next to each worktree in the tree view. Handy for spotting stale worktrees at a glance.
93+
Available variables: `$FULL_PATH`, `$BASE_NAME`, `$RELATIVE_PATH`, `$LAST_COMMIT` (relative time of the last commit, e.g. "3 weeks ago"). Hover a worktree to see the absolute timestamp.
94+
**Example:** `"$RELATIVE_PATH · $LAST_COMMIT"`
95+
9196
- **`git-worktree-manager.worktreeCopyPatterns`**
9297
Specify files or directories to be copied into a newly created worktree
9398
(for example, local config files or environment-specific assets).

README.zh-CN.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ Git Worktree Manager 将 worktree 管理能力直接集成到 VS Code 中,
8888
- **`git-worktree-manager.treeView.toSCM`**
8989
在源码管理(Source Control)视图中显示 worktree。
9090

91+
- **`git-worktree-manager.treeView.worktreeDescriptionTemplate`**
92+
自定义 worktree 在树视图中显示的描述文本,便于快速识别陈旧的 worktree。
93+
可用变量:`$FULL_PATH``$BASE_NAME``$RELATIVE_PATH``$LAST_COMMIT`(最后一次提交的相对时间,例如 “3 周前”)。鼠标悬停可查看绝对时间戳。
94+
**示例:** `"$RELATIVE_PATH · $LAST_COMMIT"`
95+
9196
- **`git-worktree-manager.worktreeCopyPatterns`**
9297
指定在创建新 worktree 时需要复制的文件或目录
9398
(例如本地配置文件或环境相关资源)。

l10n/bundle.l10n.ja.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"Push commit ( {0} → {1} ) on {2}": "{2} で コミット ( {0} → {1} ) をプッシュ",
6969
"$(arrow-up) Ahead commits {0}\n\n": "$(arrow-up) プッシュ可能なコミット {0}\n\n",
7070
"$(arrow-down) Behind commits {0}\n\n": "$(arrow-down) プル可能なコミット {0}\n\n",
71+
"$(history) Last commit {0} _({1})_\n\n": "$(history) 最終コミット {0} _({1})_\n\n",
7172
"*Click to open this worktree in a new window*\n\n": "*クリックしてこのワークツリーを新しいウィンドウで開く*\n\n",
7273
"$(folder) folder {0}\n\n": "$(folder) フォルダ {0}\n\n",
7374
"$(file) file {0}\n\n": "$(file) ファイル {0}\n\n",

l10n/bundle.l10n.zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"Push commit ( {0} → {1} ) on {2}": "推送提交 ({0} → {1}) 于 {2}",
6969
"$(arrow-up) Ahead commits {0}\n\n": "$(arrow-up) 可推送提交 {0}\n\n",
7070
"$(arrow-down) Behind commits {0}\n\n": "$(arrow-down) 可拉取提交 {0}\n\n",
71+
"$(history) Last commit {0} _({1})_\n\n": "$(history) 最后提交 {0} _({1})_\n\n",
7172
"*Click to open this worktree in a new window*\n\n": "*点击用新窗口打开该 Worktree*\n\n",
7273
"$(folder) folder {0}\n\n": "$(folder) 文件夹 {0}\n\n",
7374
"$(file) file {0}\n\n": "$(file) 文件 {0}\n\n",

l10n/bundle.l10n.zh-tw.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"Push commit ( {0} → {1} ) on {2}": "推送提交 ( {0} → {1} ) 於 {2}",
6969
"$(arrow-up) Ahead commits {0}\n\n": "$(arrow-up) 可推送提交 {0}\n\n",
7070
"$(arrow-down) Behind commits {0}\n\n": "$(arrow-down) 可拉取提交 {0}\n\n",
71+
"$(history) Last commit {0} _({1})_\n\n": "$(history) 最後提交 {0} _({1})_\n\n",
7172
"*Click to open this worktree in a new window*\n\n": "*點擊以在新視窗開啟此 Worktree*\n\n",
7273
"$(folder) folder {0}\n\n": "$(folder) 資料夾 {0}\n\n",
7374
"$(file) file {0}\n\n": "$(file) 檔案 {0}\n\n",

package.nls.ja.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@
105105
"config.worktreeSubdirectoryTemplate.patternErrorMessage": "テンプレートに次の文字は使用できません:/ \\ : * ? \" < > |",
106106
"config.postCreateCmd.description": "ワークツリー作成後に実行するコマンド。デフォルトでは、新しいワークツリーのディレクトリ内で実行されます。コマンドで使用できる変数:\n\n- `$BASE_PATH`:ワークツリーの完全パス\n- `$WORKTREE_PATH`:ワークツリーの完全パス\n- `$BASE_NAME`:ワークツリーのフォルダ名\n\n例:\n`git submodule update --init --recursive`",
107107
"config.preRemoveCmd.description": "ワークツリー削除前に実行するコマンド。ワークツリーのディレクトリ内で実行されます。コマンドが失敗またはキャンセルされた場合、削除は中止されます。コマンドで使用できる変数:\n\n- `$BASE_PATH`:メインリポジトリの完全パス\n- `$WORKTREE_PATH`:削除対象ワークツリーの完全パス\n\n例:\n`pnpm run worktree:teardown-db`",
108-
"config.worktreeDescriptionTemplate.description": "ワークツリーの説明テンプレートです。使用可能な変数:\n\n- `$FULL_PATH`:ワークツリーの完全パス\n- `$BASE_NAME`:ワークツリーのフォルダ名\n- `$RELATIVE_PATH`:相対パス(メインリポジトリのルートからの相対パス)",
108+
"config.worktreeDescriptionTemplate.description": "ワークツリーの説明テンプレートです。使用可能な変数:\n\n- `$FULL_PATH`:ワークツリーの完全パス\n- `$BASE_NAME`:ワークツリーのフォルダ名\n- `$RELATIVE_PATH`:相対パス(メインリポジトリのルートからの相対パス)\n- `$LAST_COMMIT`:このワークツリーの最終コミットからの相対時間(例:「3週間前」)。古いワークツリーの識別に便利です。",
109109
"config.terminalNameTemplate.description": "内蔵ターミナルの名称テンプレートです。使用可能な変数:\n\n- `$FULL_PATH`:フォルダの完全パス\n- `$BASE_NAME`:フォルダ名\n- `$LABEL`:表示名、フォルダ名またはワークツリーの表示名"
110110
}

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@
105105
"config.worktreeSubdirectoryTemplate.patternErrorMessage": "Template cannot contain characters: / \\ : * ? \" < > |",
106106
"config.postCreateCmd.description": "Command to execute after creating a worktree. The default execution path is the directory of the newly created worktree. You can use the following variables in the command:\n\n- `$BASE_PATH`: The full path of the worktree.\n- `$WORKTREE_PATH`: The full path of the worktree.\n\nExample:\n`git submodule update --init --recursive`",
107107
"config.preRemoveCmd.description": "Command to execute before removing a worktree. Runs inside the worktree directory. If the command fails or is cancelled, removal is aborted. You can use the following variables in the command:\n\n- `$BASE_PATH`: The full path of the main repository.\n- `$WORKTREE_PATH`: The full path of the worktree being removed.\n\nExample:\n`pnpm run worktree:teardown-db`",
108-
"config.worktreeDescriptionTemplate.description": "Template for the worktree description. Available variables:\n\n- `$FULL_PATH`: The full path of the worktree.\n- `$BASE_NAME`: The folder name of the worktree.\n- `$RELATIVE_PATH`: The relative path (relative to the main repo directory).",
108+
"config.worktreeDescriptionTemplate.description": "Template for the worktree description. Available variables:\n\n- `$FULL_PATH`: The full path of the worktree.\n- `$BASE_NAME`: The folder name of the worktree.\n- `$RELATIVE_PATH`: The relative path (relative to the main repo directory).\n- `$LAST_COMMIT`: Relative time of the last commit on this worktree (e.g. \"3 weeks ago\"), useful for spotting stale worktrees.",
109109
"config.terminalNameTemplate.description": "Template for the terminal name. Available variables:\n\n- `$FULL_PATH`: The full path of the folder.\n- `$BASE_NAME`: The folder name.\n- `$LABEL`: The display name, the folder name or the worktree display name."
110110
}

package.nls.zh-cn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@
105105
"config.worktreeSubdirectoryTemplate.patternErrorMessage": "模板不能包含以下字符:/ \\ : * ? \" < > |",
106106
"config.postCreateCmd.description": "创建 Worktree 后执行的命令,默认执行路径是新创建的 Worktree 的目录内。你可以在命令中使用以下变量:\n\n- `$BASE_PATH`:仓库的完整路径。\n- `$WORKTREE_PATH`:Worktree 的完整路径。\n\n示例:\n`git submodule update --init --recursive`",
107107
"config.preRemoveCmd.description": "删除 Worktree 前执行的命令,在 Worktree 目录内执行。如果命令执行失败或被取消,则中止删除操作。你可以在命令中使用以下变量:\n\n- `$BASE_PATH`:主仓库的完整路径。\n- `$WORKTREE_PATH`:即将被删除的 Worktree 的完整路径。\n\n示例:\n`pnpm run worktree:teardown-db`",
108-
"config.worktreeDescriptionTemplate.description": "Worktree 描述的模板。可用的变量:\n\n- `$FULL_PATH`:Worktree 的完整路径。\n- `$BASE_NAME`:Worktree 的文件夹名称。\n- `$RELATIVE_PATH`:相对路径(相对于主仓库目录)。",
108+
"config.worktreeDescriptionTemplate.description": "Worktree 描述的模板。可用的变量:\n\n- `$FULL_PATH`:Worktree 的完整路径。\n- `$BASE_NAME`:Worktree 的文件夹名称。\n- `$RELATIVE_PATH`:相对路径(相对于主仓库目录)。\n- `$LAST_COMMIT`:该 worktree 最后一次提交的相对时间(例如 “3 周前”),便于识别陈旧的 worktree。",
109109
"config.terminalNameTemplate.description": "打开内置终端时显示的名称模板。可用的变量:\n\n- `$FULL_PATH`:文件夹的完整路径。\n- `$BASE_NAME`:文件夹名称。\n- `$LABEL`:展示的名称、文件夹名称或者 Worktree 展示的名称"
110110
}

package.nls.zh-tw.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@
105105
"config.worktreeSubdirectoryTemplate.patternErrorMessage": "範本不能包含以下字元:/ \\ : * ? \" < > |",
106106
"config.postCreateCmd.description": "建立 Worktree 後執行的命令。預設執行路徑是新建立的 Worktree 的目錄內。你可以在命令中使用以下變數:\n\n- `$BASE_PATH`:Worktree 的完整路徑。\n- `$WORKTREE_PATH`:Worktree 的完整路徑。\n\n範例:\n`git submodule update --init --recursive`",
107107
"config.preRemoveCmd.description": "移除 Worktree 前執行的命令,在 Worktree 目錄內執行。若命令執行失敗或被取消,則中止移除。你可以在命令中使用以下變數:\n\n- `$BASE_PATH`:主倉庫的完整路徑。\n- `$WORKTREE_PATH`:即將被移除的 Worktree 的完整路徑。\n\n範例:\n`pnpm run worktree:teardown-db`",
108-
"config.worktreeDescriptionTemplate.description": "Worktree 描述的模板。可用的變數:\n\n- `$FULL_PATH`:Worktree 的完整路徑。\n- `$BASE_NAME`:Worktree 的資料夾名稱。\n- `$RELATIVE_PATH`:相對路徑(相對於主倉庫目錄)。",
108+
"config.worktreeDescriptionTemplate.description": "Worktree 描述的模板。可用的變數:\n\n- `$FULL_PATH`:Worktree 的完整路徑。\n- `$BASE_NAME`:Worktree 的資料夾名稱。\n- `$RELATIVE_PATH`:相對路徑(相對於主倉庫目錄)。\n- `$LAST_COMMIT`:該 worktree 最後一次提交的相對時間(例如「3 週前」),便於識別陳舊的 worktree。",
109109
"config.terminalNameTemplate.description": "開啟內建終端機時顯示的名稱模板。可用的變數:\n\n- `$FULL_PATH`:資料夾的完整路徑。\n- `$BASE_NAME`:資料夾名稱。\n- `$LABEL`:展示的名稱、資料夾名稱或者 Worktree 展示的名稱"
110110
}

src/core/git/getWorktreeList.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import folderRoot from '@/core/folderRoot';
22
import { execBase } from '@/core/git/exec-base';
33
import { getNameRev } from '@/core/git/getNameRev';
44
import { getMainFolder } from '@/core/git/getMainFolder';
5+
import { getLashCommitDetail } from '@/core/git/getLashCommitDetail';
56
import { comparePath, toSimplePath } from '@/core/util/path';
67
import type { IWorktreeDetail, IWorktreeOutputItem } from '@/types';
78
import logger from '@/core/log/logger';
@@ -66,6 +67,12 @@ async function buildWorktreeDetail(item: IWorktreeOutputItem, mainFolder: string
6667

6768
const hash = item.HEAD || '';
6869

70+
let lastCommitDate: string | undefined;
71+
if (!isBare && !prunable) {
72+
const detail = await getLashCommitDetail(worktreePath, ['cI']);
73+
lastCommitDate = detail.cI || undefined;
74+
}
75+
6976
return {
7077
name,
7178
path: worktreePath,
@@ -78,6 +85,7 @@ async function buildWorktreeDetail(item: IWorktreeOutputItem, mainFolder: string
7885
isMain,
7986
hash,
8087
mainFolder: mainFolderPath,
88+
lastCommitDate,
8189
};
8290
}
8391

0 commit comments

Comments
 (0)