Skip to content

Commit e4d5dd8

Browse files
committed
feat: add $BASE_ROOT variable support and update worktree path template
- Add $BASE_ROOT variable to worktree path template system - $BASE_ROOT represents the parent directory of the repository root - Implement variable replacement in getBaseWorktreeDir function - Update default worktree path template to support the new variable - Update all localization files (en, zh-cn, zh-tw, ja) with $BASE_ROOT documentation
1 parent 3352f08 commit e4d5dd8

7 files changed

Lines changed: 11 additions & 9 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,8 @@
943943
"git-worktree-manager.worktreePathTemplate": {
944944
"order": 11,
945945
"type": "string",
946-
"default": "$BASE_PATH.worktree",
947-
"description": "%config.worktreePathTemplate.description%"
946+
"default": "$BASE_PATH.worktrees",
947+
"markdownDescription": "%config.worktreePathTemplate.description%"
948948
},
949949
"git-worktree-manager.worktreeSubdirectoryTemplate": {
950950
"order": 12,

package.nls.ja.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"config.checkoutIgnoreOtherWorktree.description": "有効にすると、ブランチの切り替え時に他のワークツリーの状態を無視し、複数のワークツリーで同じブランチを使用できるようになります",
101101
"config.branchPick.showRenameBranch.description": "「ブランチを選択」の結果に「ブランチのリネーム」ボタンを表示",
102102
"config.treeView.toSCM.description": "ソース管理コンテナにビューを表示",
103-
"config.worktreePathTemplate.description": "ワークツリーパスのテンプレートです。使用可能な変数:$BASE_PATH(リポジトリのルート)",
103+
"config.worktreePathTemplate.description": "ワークツリーパスのテンプレートです。使用可能な変数:\n\n- `$BASE_PATH`(リポジトリのルート\n- `$BASE_ROOT`(リポジトリのルートの親ディレクトリ",
104104
"config.worktreeSubdirectoryTemplate.description": "ワークツリーサブディレクトリ名のテンプレートです。使用可能な変数:\n\n- `$BASE_NAME`(リポジトリフォルダ名)\n- `$INDEX`(増分番号)。\n- `$REF_NAME` (参照名、ブランチ名やタグ名など)\n\n使用できない文字:/ \\ : * ? \" < > |",
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`",

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"config.checkoutIgnoreOtherWorktree.description": "When enabled, the state of other worktrees is ignored when switching branches, allowing multiple worktrees to use the same branch.",
101101
"config.branchPick.showRenameBranch.description": "Show the \"Rename Branch\" button on the results of \"Pick Branch\"",
102102
"config.treeView.toSCM.description": "Display views in the Source Control container",
103-
"config.worktreePathTemplate.description": "Template for the worktree path. Available variables: $BASE_PATH (repo root).",
103+
"config.worktreePathTemplate.description": "Template for the worktree path. Available variables:\n\n- `$BASE_PATH` (repo root)\n- `$BASE_ROOT` (parent directory of repo root).",
104104
"config.worktreeSubdirectoryTemplate.description": "Template for worktree subdirectory names. Available variables:\n\n- `$BASE_NAME` (repo folder name)\n- `$INDEX` (incrementing number).\n- `$REF_NAME` (reference name, such as branch name, tag name)\n\nCannot contain characters: / \\ : * ? \" < > |",
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`",

package.nls.zh-cn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"config.checkoutIgnoreOtherWorktree.description": "启用后,在切换分支时会忽略其他 Worktree 的状态,允许多个 Worktree 使用相同分支",
101101
"config.branchPick.showRenameBranch.description": "\"挑选分支\" 列表中显示 \"重命名分支\" 按钮",
102102
"config.treeView.toSCM.description": "在源代码管理容器中显示视图",
103-
"config.worktreePathTemplate.description": "Worktree 路径的模板。可用的变量:$BASE_PATH(仓库根目录)",
103+
"config.worktreePathTemplate.description": "Worktree 路径的模板。可用的变量:\n\n- `$BASE_PATH`(仓库根目录\n- `$BASE_ROOT`(仓库根目录的父目录",
104104
"config.worktreeSubdirectoryTemplate.description": "Worktree 子目录名称的模板。可用的变量:\n\n- `$BASE_NAME`(仓库文件夹名称)\n- `$INDEX`(递增数字)。\n- `$REF_NAME` (引用名称,如分支名、标签名)\n\n不能包含字符:/ \\ : * ? \" < > |",
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`",

package.nls.zh-tw.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"config.checkoutIgnoreOtherWorktree.description": "啟用後,在切換分支時會忽略其他 Worktree 的狀態,允許多個 Worktree 使用相同分支",
101101
"config.branchPick.showRenameBranch.description": "在「挑選分支」結果中顯示「重命名分支」按鈕",
102102
"config.treeView.toSCM.description": "在原始碼控制容器中顯示視圖",
103-
"config.worktreePathTemplate.description": "Worktree 路徑的模板。可用的變數:$BASE_PATH(倉庫根目錄)",
103+
"config.worktreePathTemplate.description": "Worktree 路徑的模板。可用的變數:\n\n- `$BASE_PATH`(倉庫根目錄\n- `$BASE_ROOT`(倉庫根目錄的父目錄",
104104
"config.worktreeSubdirectoryTemplate.description": "Worktree 子目錄名稱的模板。可用的變數:\n\n- `$BASE_NAME`(倉庫資料夾名稱)\n- `$INDEX`(遞增數字)。\n- `$REF_NAME` (引用名稱,如分支名、標籤名)\n\n不能包含字元:/ \\ : * ? \" < > |",
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`",

src/core/config/setting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class Config {
6666
static get(key: 'treeView.worktreeDescriptionTemplate', defaultValue: '$FULL_PATH'): string;
6767

6868
// Path template configuration
69-
static get(key: 'worktreePathTemplate', defaultValue: '$BASE_PATH.worktree'): string;
69+
static get(key: 'worktreePathTemplate', defaultValue: '$BASE_PATH.worktrees'): string;
7070
static get(key: 'worktreeSubdirectoryTemplate', defaultValue: '$BASE_NAME$INDEX'): string;
7171

7272
// Post-creation command configuration

src/core/util/folder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ export function getGitFolderByUri(uri: vscode.Uri) {
4141

4242
// get worktree base dir
4343
export const getBaseWorktreeDir = (baseDir: string) => {
44-
const worktreePathTemplate = Config.get('worktreePathTemplate', '$BASE_PATH.worktree');
45-
return worktreePathTemplate.replace('$BASE_PATH', baseDir);
44+
const worktreePathTemplate = Config.get('worktreePathTemplate', '$BASE_PATH.worktrees');
45+
return worktreePathTemplate
46+
.replace('$BASE_PATH', baseDir)
47+
.replace('$BASE_ROOT', path.dirname(baseDir));
4648
};
4749

4850
// Validate template for invalid path characters

0 commit comments

Comments
 (0)