easy-worktree 0.0.5__tar.gz → 0.0.7__tar.gz
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.
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/PKG-INFO +1 -1
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/easy_worktree/__init__.py +203 -12
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/pyproject.toml +1 -1
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/.gitignore +0 -0
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/.python-version +0 -0
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/DEPLOY.md +0 -0
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/LICENSE +0 -0
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/README.md +0 -0
- {easy_worktree-0.0.5 → easy_worktree-0.0.7}/README_ja.md +0 -0
|
@@ -215,19 +215,16 @@ def get_repository_name(url: str) -> str:
|
|
|
215
215
|
|
|
216
216
|
|
|
217
217
|
def create_hook_template(base_dir: Path):
|
|
218
|
-
"""post-add hook
|
|
218
|
+
"""post-add hook のテンプレートと .wt/ 内のファイルを作成"""
|
|
219
219
|
wt_dir = base_dir / ".wt"
|
|
220
|
-
hook_file = wt_dir / "post-add"
|
|
221
|
-
|
|
222
|
-
# 既に存在する場合は何もしない
|
|
223
|
-
if hook_file.exists():
|
|
224
|
-
return
|
|
225
220
|
|
|
226
221
|
# .wt ディレクトリを作成
|
|
227
222
|
wt_dir.mkdir(exist_ok=True)
|
|
228
223
|
|
|
229
|
-
#
|
|
230
|
-
|
|
224
|
+
# post-add hook テンプレート
|
|
225
|
+
hook_file = wt_dir / "post-add"
|
|
226
|
+
if not hook_file.exists():
|
|
227
|
+
template = """#!/bin/bash
|
|
231
228
|
# Post-add hook for easy-worktree
|
|
232
229
|
# This script is automatically executed after creating a new worktree
|
|
233
230
|
#
|
|
@@ -256,10 +253,186 @@ def create_hook_template(base_dir: Path):
|
|
|
256
253
|
#
|
|
257
254
|
# echo "Setup completed!"
|
|
258
255
|
"""
|
|
256
|
+
hook_file.write_text(template)
|
|
257
|
+
# 実行権限を付与
|
|
258
|
+
hook_file.chmod(0o755)
|
|
259
|
+
|
|
260
|
+
# .gitignore
|
|
261
|
+
gitignore_file = wt_dir / ".gitignore"
|
|
262
|
+
if not gitignore_file.exists():
|
|
263
|
+
gitignore_content = "post-add.local\n"
|
|
264
|
+
gitignore_file.write_text(gitignore_content)
|
|
265
|
+
|
|
266
|
+
# README.md (言語に応じて)
|
|
267
|
+
readme_file = wt_dir / "README.md"
|
|
268
|
+
if not readme_file.exists():
|
|
269
|
+
if is_japanese():
|
|
270
|
+
readme_content = """# easy-worktree フック
|
|
271
|
+
|
|
272
|
+
このディレクトリには、easy-worktree (wt コマンド) のフックスクリプトが格納されています。
|
|
273
|
+
|
|
274
|
+
## wt コマンドとは
|
|
275
|
+
|
|
276
|
+
`wt` は Git worktree を簡単に管理するための CLI ツールです。複数のブランチで同時に作業する際に、ブランチごとに独立したディレクトリ(worktree)を作成・管理できます。
|
|
277
|
+
|
|
278
|
+
### 基本的な使い方
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
# リポジトリをクローン
|
|
282
|
+
wt clone <repository_url>
|
|
283
|
+
|
|
284
|
+
# 新しい worktree を作成(新規ブランチ)
|
|
285
|
+
wt add <作業名>
|
|
286
|
+
|
|
287
|
+
# 既存ブランチから worktree を作成
|
|
288
|
+
wt add <作業名> <既存ブランチ名>
|
|
289
|
+
|
|
290
|
+
# エイリアスを作成(current エイリアスで現在の作業を切り替え)
|
|
291
|
+
wt add <作業名> --alias current
|
|
292
|
+
|
|
293
|
+
# worktree 一覧を表示
|
|
294
|
+
wt list
|
|
295
|
+
|
|
296
|
+
# worktree を削除
|
|
297
|
+
wt rm <作業名>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
詳細は https://github.com/igtm/easy-worktree を参照してください。
|
|
301
|
+
|
|
302
|
+
## エイリアスとは
|
|
303
|
+
|
|
304
|
+
エイリアスは、worktree へのシンボリックリンク(symbolic link)です。同じエイリアス名で異なる worktree を指すことで、固定されたパスで複数のブランチを切り替えられます。
|
|
305
|
+
|
|
306
|
+
### エイリアスの便利な使い方
|
|
307
|
+
|
|
308
|
+
**VSCode ワークスペースでの活用**
|
|
309
|
+
|
|
310
|
+
`current` などの固定エイリアスを VSCode のワークスペースとして開くことで、worktree を切り替えても VSCode を開き直す必要がなくなります。
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# 最初の作業
|
|
314
|
+
wt add feature-a --alias current
|
|
315
|
+
code current # VSCode で current を開く
|
|
316
|
+
|
|
317
|
+
# 別の作業に切り替え(VSCode は開いたまま)
|
|
318
|
+
wt add feature-b --alias current
|
|
319
|
+
# current エイリアスが feature-b を指すようになる
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
このように、エイリアスを使うことで:
|
|
323
|
+
- VSCode のワークスペース設定が維持される
|
|
324
|
+
- 拡張機能の設定やウィンドウレイアウトが保持される
|
|
325
|
+
- ブランチ切り替えのたびにエディタを開き直す手間が不要
|
|
326
|
+
|
|
327
|
+
## post-add フック
|
|
328
|
+
|
|
329
|
+
`post-add` フックは、worktree 作成後に自動実行されるスクリプトです。
|
|
330
|
+
|
|
331
|
+
### 使用例
|
|
332
|
+
|
|
333
|
+
- 依存関係のインストール(npm install, pip install など)
|
|
334
|
+
- 設定ファイルのコピー(.env ファイルなど)
|
|
335
|
+
- ディレクトリの初期化
|
|
336
|
+
- VSCode ワークスペースの作成
|
|
337
|
+
|
|
338
|
+
### 利用可能な環境変数
|
|
339
|
+
|
|
340
|
+
- `WT_WORKTREE_PATH`: 作成された worktree のパス
|
|
341
|
+
- `WT_WORKTREE_NAME`: worktree の名前
|
|
342
|
+
- `WT_BASE_DIR`: _base/ ディレクトリのパス
|
|
343
|
+
- `WT_BRANCH`: ブランチ名
|
|
344
|
+
- `WT_ACTION`: アクション名(常に "add")
|
|
345
|
+
|
|
346
|
+
### post-add.local について
|
|
347
|
+
|
|
348
|
+
`post-add.local` は、個人用のローカルフックです。このファイルは `.gitignore` に含まれているため、リポジトリにコミットされません。チーム全体で共有したいフックは `post-add` に、個人的な設定は `post-add.local` に記述してください。
|
|
349
|
+
|
|
350
|
+
`post-add` が存在する場合のみ、`post-add.local` も自動的に実行されます。
|
|
351
|
+
"""
|
|
352
|
+
else:
|
|
353
|
+
readme_content = """# easy-worktree Hooks
|
|
354
|
+
|
|
355
|
+
This directory contains hook scripts for easy-worktree (wt command).
|
|
356
|
+
|
|
357
|
+
## What is wt command?
|
|
259
358
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
359
|
+
`wt` is a CLI tool for easily managing Git worktrees. When working on multiple branches simultaneously, you can create and manage independent directories (worktrees) for each branch.
|
|
360
|
+
|
|
361
|
+
### Basic Usage
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
# Clone a repository
|
|
365
|
+
wt clone <repository_url>
|
|
366
|
+
|
|
367
|
+
# Create a new worktree (new branch)
|
|
368
|
+
wt add <work_name>
|
|
369
|
+
|
|
370
|
+
# Create a worktree from an existing branch
|
|
371
|
+
wt add <work_name> <existing_branch_name>
|
|
372
|
+
|
|
373
|
+
# Create an alias (use "current" alias to switch between tasks)
|
|
374
|
+
wt add <work_name> --alias current
|
|
375
|
+
|
|
376
|
+
# List worktrees
|
|
377
|
+
wt list
|
|
378
|
+
|
|
379
|
+
# Remove a worktree
|
|
380
|
+
wt rm <work_name>
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
For more details, see https://github.com/igtm/easy-worktree
|
|
384
|
+
|
|
385
|
+
## What are Aliases?
|
|
386
|
+
|
|
387
|
+
Aliases are symbolic links to worktrees. By pointing the same alias name to different worktrees, you can switch between multiple branches using a fixed path.
|
|
388
|
+
|
|
389
|
+
### Smart Use of Aliases
|
|
390
|
+
|
|
391
|
+
**Using with VSCode Workspace**
|
|
392
|
+
|
|
393
|
+
By opening a fixed alias like `current` as a VSCode workspace, you can switch worktrees without needing to reopen VSCode.
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
# First task
|
|
397
|
+
wt add feature-a --alias current
|
|
398
|
+
code current # Open current in VSCode
|
|
399
|
+
|
|
400
|
+
# Switch to another task (VSCode stays open)
|
|
401
|
+
wt add feature-b --alias current
|
|
402
|
+
# The current alias now points to feature-b
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
Benefits of using aliases:
|
|
406
|
+
- VSCode workspace settings are preserved
|
|
407
|
+
- Extension settings and window layouts are maintained
|
|
408
|
+
- No need to reopen the editor when switching branches
|
|
409
|
+
|
|
410
|
+
## post-add Hook
|
|
411
|
+
|
|
412
|
+
The `post-add` hook is a script that runs automatically after creating a worktree.
|
|
413
|
+
|
|
414
|
+
### Use Cases
|
|
415
|
+
|
|
416
|
+
- Install dependencies (npm install, pip install, etc.)
|
|
417
|
+
- Copy configuration files (.env files, etc.)
|
|
418
|
+
- Initialize directories
|
|
419
|
+
- Create VSCode workspaces
|
|
420
|
+
|
|
421
|
+
### Available Environment Variables
|
|
422
|
+
|
|
423
|
+
- `WT_WORKTREE_PATH`: Path to the created worktree
|
|
424
|
+
- `WT_WORKTREE_NAME`: Name of the worktree
|
|
425
|
+
- `WT_BASE_DIR`: Path to the _base/ directory
|
|
426
|
+
- `WT_BRANCH`: Branch name
|
|
427
|
+
- `WT_ACTION`: Action name (always "add")
|
|
428
|
+
|
|
429
|
+
### About post-add.local
|
|
430
|
+
|
|
431
|
+
`post-add.local` is for personal local hooks. This file is included in `.gitignore`, so it won't be committed to the repository. Use `post-add` for hooks you want to share with the team, and `post-add.local` for your personal settings.
|
|
432
|
+
|
|
433
|
+
`post-add.local` is automatically executed only when `post-add` exists.
|
|
434
|
+
"""
|
|
435
|
+
readme_file.write_text(readme_content)
|
|
263
436
|
|
|
264
437
|
|
|
265
438
|
def find_base_dir() -> Path | None:
|
|
@@ -441,6 +614,24 @@ def cmd_add(args: list[str]):
|
|
|
441
614
|
print(msg('fetching'))
|
|
442
615
|
run_command(["git", "fetch", "--all"], cwd=base_dir)
|
|
443
616
|
|
|
617
|
+
# _base/ を base branch の最新に更新
|
|
618
|
+
# 現在のブランチを取得
|
|
619
|
+
result = run_command(
|
|
620
|
+
["git", "rev-parse", "--abbrev-ref", "HEAD"],
|
|
621
|
+
cwd=base_dir,
|
|
622
|
+
check=False
|
|
623
|
+
)
|
|
624
|
+
if result.returncode == 0:
|
|
625
|
+
current_branch = result.stdout.strip()
|
|
626
|
+
# リモートブランチが存在する場合は pull
|
|
627
|
+
result = run_command(
|
|
628
|
+
["git", "rev-parse", "--verify", f"origin/{current_branch}"],
|
|
629
|
+
cwd=base_dir,
|
|
630
|
+
check=False
|
|
631
|
+
)
|
|
632
|
+
if result.returncode == 0:
|
|
633
|
+
run_command(["git", "pull", "origin", current_branch], cwd=base_dir, check=False)
|
|
634
|
+
|
|
444
635
|
# ブランチ名が指定されている場合は既存ブランチをチェックアウト
|
|
445
636
|
# 指定されていない場合は新しいブランチを作成
|
|
446
637
|
branch_name = None
|
|
@@ -988,7 +1179,7 @@ def show_help():
|
|
|
988
1179
|
|
|
989
1180
|
def show_version():
|
|
990
1181
|
"""Show version information"""
|
|
991
|
-
print("easy-worktree version 0.0.
|
|
1182
|
+
print("easy-worktree version 0.0.7")
|
|
992
1183
|
|
|
993
1184
|
|
|
994
1185
|
def main():
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|