easy-worktree 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl
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/__init__.py +96 -24
- {easy_worktree-0.1.2.dist-info → easy_worktree-0.1.4.dist-info}/METADATA +13 -2
- easy_worktree-0.1.4.dist-info/RECORD +6 -0
- easy_worktree-0.1.2.dist-info/RECORD +0 -6
- {easy_worktree-0.1.2.dist-info → easy_worktree-0.1.4.dist-info}/WHEEL +0 -0
- {easy_worktree-0.1.2.dist-info → easy_worktree-0.1.4.dist-info}/entry_points.txt +0 -0
- {easy_worktree-0.1.2.dist-info → easy_worktree-0.1.4.dist-info}/licenses/LICENSE +0 -0
easy_worktree/__init__.py
CHANGED
|
@@ -226,10 +226,11 @@ def get_repository_name(url: str) -> str:
|
|
|
226
226
|
def load_config(base_dir: Path) -> dict:
|
|
227
227
|
"""設定ファイルを読み込む"""
|
|
228
228
|
config_file = base_dir / ".wt" / "config.toml"
|
|
229
|
+
local_config_file = base_dir / ".wt" / "config.local.toml"
|
|
230
|
+
|
|
229
231
|
default_config = {
|
|
230
232
|
"worktrees_dir": ".worktrees",
|
|
231
233
|
"setup_files": [".env"],
|
|
232
|
-
"auto_copy_on_add": True,
|
|
233
234
|
}
|
|
234
235
|
|
|
235
236
|
if config_file.exists():
|
|
@@ -240,6 +241,14 @@ def load_config(base_dir: Path) -> dict:
|
|
|
240
241
|
except Exception as e:
|
|
241
242
|
print(msg("error", f"Failed to load config: {e}"), file=sys.stderr)
|
|
242
243
|
|
|
244
|
+
if local_config_file.exists():
|
|
245
|
+
try:
|
|
246
|
+
with open(local_config_file, "r", encoding="utf-8") as f:
|
|
247
|
+
local_config = toml.load(f)
|
|
248
|
+
default_config.update(local_config)
|
|
249
|
+
except Exception as e:
|
|
250
|
+
print(msg("error", f"Failed to load local config: {e}"), file=sys.stderr)
|
|
251
|
+
|
|
243
252
|
return default_config
|
|
244
253
|
|
|
245
254
|
|
|
@@ -268,7 +277,6 @@ def create_hook_template(base_dir: Path):
|
|
|
268
277
|
{
|
|
269
278
|
"worktrees_dir": ".worktrees",
|
|
270
279
|
"setup_files": [".env"],
|
|
271
|
-
"auto_copy_on_add": True,
|
|
272
280
|
},
|
|
273
281
|
)
|
|
274
282
|
|
|
@@ -331,9 +339,24 @@ def create_hook_template(base_dir: Path):
|
|
|
331
339
|
|
|
332
340
|
# .gitignore
|
|
333
341
|
gitignore_file = wt_dir / ".gitignore"
|
|
342
|
+
|
|
343
|
+
ignores = ["post-add.local", "config.local.toml", "last_selection"]
|
|
344
|
+
|
|
334
345
|
if not gitignore_file.exists():
|
|
335
|
-
gitignore_content = "
|
|
346
|
+
gitignore_content = "\n".join(ignores) + "\n"
|
|
336
347
|
gitignore_file.write_text(gitignore_content)
|
|
348
|
+
else:
|
|
349
|
+
content = gitignore_file.read_text()
|
|
350
|
+
updated = False
|
|
351
|
+
for ignore in ignores:
|
|
352
|
+
if ignore not in content:
|
|
353
|
+
if content and not content.endswith("\n"):
|
|
354
|
+
content += "\n"
|
|
355
|
+
content += f"{ignore}\n"
|
|
356
|
+
updated = True
|
|
357
|
+
if updated:
|
|
358
|
+
gitignore_file.write_text(content)
|
|
359
|
+
|
|
337
360
|
|
|
338
361
|
# README.md (言語に応じて)
|
|
339
362
|
readme_file = wt_dir / "README.md"
|
|
@@ -356,6 +379,9 @@ wt clone <repository_url>
|
|
|
356
379
|
# 新しい worktree を作成(新規ブランチ)
|
|
357
380
|
wt add <作業名>
|
|
358
381
|
|
|
382
|
+
# セットアップ(フック実行など)をスキップして作成
|
|
383
|
+
wt add <作業名> --skip-setup
|
|
384
|
+
|
|
359
385
|
# 既存ブランチから worktree を作成
|
|
360
386
|
wt add <作業名> <既存ブランチ名>
|
|
361
387
|
|
|
@@ -368,6 +394,19 @@ wt rm <作業名>
|
|
|
368
394
|
|
|
369
395
|
詳細は https://github.com/igtm/easy-worktree を参照してください。
|
|
370
396
|
|
|
397
|
+
## 設定 (config.toml)
|
|
398
|
+
|
|
399
|
+
`.wt/config.toml` で以下の設定が可能です。
|
|
400
|
+
|
|
401
|
+
```toml
|
|
402
|
+
worktrees_dir = ".worktrees" # worktree を作成するディレクトリ名
|
|
403
|
+
setup_files = [".env"] # 自動セットアップでコピーするファイル一覧
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### ローカル設定 (config.local.toml)
|
|
407
|
+
|
|
408
|
+
`config.local.toml` を作成すると、設定をローカルでのみ上書きできます。このファイルは自動的に `.gitignore` に追加され、リポジトリにはコミットされません。
|
|
409
|
+
|
|
371
410
|
## post-add フック
|
|
372
411
|
|
|
373
412
|
`post-add` フックは、worktree 作成後に自動実行されるスクリプトです。
|
|
@@ -411,6 +450,9 @@ wt clone <repository_url>
|
|
|
411
450
|
# Create a new worktree (new branch)
|
|
412
451
|
wt add <work_name>
|
|
413
452
|
|
|
453
|
+
# Skip setup (hook execution etc)
|
|
454
|
+
wt add <work_name> --skip-setup
|
|
455
|
+
|
|
414
456
|
# Create a worktree from an existing branch
|
|
415
457
|
wt add <work_name> <existing_branch_name>
|
|
416
458
|
|
|
@@ -423,6 +465,19 @@ wt remove <work_name>
|
|
|
423
465
|
|
|
424
466
|
For more details, see https://github.com/igtm/easy-worktree
|
|
425
467
|
|
|
468
|
+
## Configuration (config.toml)
|
|
469
|
+
|
|
470
|
+
You can customize behavior in `.wt/config.toml`:
|
|
471
|
+
|
|
472
|
+
```toml
|
|
473
|
+
worktrees_dir = ".worktrees" # Directory where worktrees are created
|
|
474
|
+
setup_files = [".env"] # Files to auto-copy during setup
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### Local Configuration (config.local.toml)
|
|
478
|
+
|
|
479
|
+
You can create `config.local.toml` to override settings locally. This file is automatically added to `.gitignore` and serves as a local override that won't be committed.
|
|
480
|
+
|
|
426
481
|
## post-add Hook
|
|
427
482
|
|
|
428
483
|
The `post-add` hook is a script that runs automatically after creating a worktree.
|
|
@@ -607,6 +662,7 @@ def add_worktree(
|
|
|
607
662
|
branch_to_use: str = None,
|
|
608
663
|
new_branch_base: str = None,
|
|
609
664
|
base_dir: Path = None,
|
|
665
|
+
skip_setup: bool = False,
|
|
610
666
|
) -> Path:
|
|
611
667
|
"""Core logic to add a worktree, reused by cmd_add and cmd_stash"""
|
|
612
668
|
if not base_dir:
|
|
@@ -616,24 +672,24 @@ def add_worktree(
|
|
|
616
672
|
print(msg("run_in_wt_dir"), file=sys.stderr)
|
|
617
673
|
sys.exit(1)
|
|
618
674
|
|
|
619
|
-
#
|
|
675
|
+
# settings loading
|
|
620
676
|
config = load_config(base_dir)
|
|
621
677
|
worktrees_dir_name = config.get("worktrees_dir", ".worktrees")
|
|
622
678
|
worktrees_dir = base_dir / worktrees_dir_name
|
|
623
679
|
worktrees_dir.mkdir(exist_ok=True)
|
|
624
680
|
|
|
625
|
-
# worktree
|
|
681
|
+
# worktree path decision
|
|
626
682
|
worktree_path = worktrees_dir / work_name
|
|
627
683
|
|
|
628
684
|
if worktree_path.exists():
|
|
629
685
|
print(msg("error", msg("already_exists", worktree_path)), file=sys.stderr)
|
|
630
686
|
sys.exit(1)
|
|
631
687
|
|
|
632
|
-
#
|
|
688
|
+
# update branch
|
|
633
689
|
print(msg("fetching"), file=sys.stderr)
|
|
634
690
|
run_command(["git", "fetch", "--all"], cwd=base_dir)
|
|
635
691
|
|
|
636
|
-
#
|
|
692
|
+
# main update to base branch latest
|
|
637
693
|
result = run_command(
|
|
638
694
|
["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=base_dir, check=False
|
|
639
695
|
)
|
|
@@ -649,10 +705,10 @@ def add_worktree(
|
|
|
649
705
|
["git", "pull", "origin", current_branch], cwd=base_dir, check=False
|
|
650
706
|
)
|
|
651
707
|
|
|
652
|
-
#
|
|
708
|
+
# create branch / checkout
|
|
653
709
|
final_branch_name = None
|
|
654
710
|
if new_branch_base:
|
|
655
|
-
#
|
|
711
|
+
# create new branch from base
|
|
656
712
|
final_branch_name = work_name
|
|
657
713
|
print(
|
|
658
714
|
msg("creating_branch", final_branch_name, new_branch_base), file=sys.stderr
|
|
@@ -671,7 +727,7 @@ def add_worktree(
|
|
|
671
727
|
check=False,
|
|
672
728
|
)
|
|
673
729
|
elif branch_to_use:
|
|
674
|
-
#
|
|
730
|
+
# checkout specified branch
|
|
675
731
|
final_branch_name = branch_to_use
|
|
676
732
|
print(msg("creating_worktree", worktree_path), file=sys.stderr)
|
|
677
733
|
result = run_command(
|
|
@@ -680,8 +736,8 @@ def add_worktree(
|
|
|
680
736
|
check=False,
|
|
681
737
|
)
|
|
682
738
|
else:
|
|
683
|
-
#
|
|
684
|
-
#
|
|
739
|
+
# auto detect
|
|
740
|
+
# use work_name as branch name
|
|
685
741
|
final_branch_name = work_name
|
|
686
742
|
|
|
687
743
|
check_local = run_command(
|
|
@@ -717,7 +773,7 @@ def add_worktree(
|
|
|
717
773
|
check=False,
|
|
718
774
|
)
|
|
719
775
|
else:
|
|
720
|
-
#
|
|
776
|
+
# find default branch
|
|
721
777
|
result_sym = run_command(
|
|
722
778
|
["git", "symbolic-ref", "refs/remotes/origin/HEAD", "--short"],
|
|
723
779
|
cwd=base_dir,
|
|
@@ -728,7 +784,7 @@ def add_worktree(
|
|
|
728
784
|
if result_sym.returncode == 0 and result_sym.stdout.strip():
|
|
729
785
|
detected_base = result_sym.stdout.strip()
|
|
730
786
|
else:
|
|
731
|
-
# remote/local main/master
|
|
787
|
+
# search in order: remote/local main/master
|
|
732
788
|
for b in ["origin/main", "origin/master", "main", "master"]:
|
|
733
789
|
if (
|
|
734
790
|
run_command(
|
|
@@ -742,7 +798,7 @@ def add_worktree(
|
|
|
742
798
|
break
|
|
743
799
|
|
|
744
800
|
if not detected_base:
|
|
745
|
-
#
|
|
801
|
+
# fallback to current branch
|
|
746
802
|
res_curr = run_command(
|
|
747
803
|
["git", "rev-parse", "--abbrev-ref", "HEAD"],
|
|
748
804
|
cwd=base_dir,
|
|
@@ -776,8 +832,8 @@ def add_worktree(
|
|
|
776
832
|
)
|
|
777
833
|
|
|
778
834
|
if result.returncode == 0:
|
|
779
|
-
|
|
780
|
-
|
|
835
|
+
if not skip_setup:
|
|
836
|
+
# automatic sync
|
|
781
837
|
setup_files = config.get("setup_files", [])
|
|
782
838
|
for file_name in setup_files:
|
|
783
839
|
src = base_dir / file_name
|
|
@@ -788,8 +844,9 @@ def add_worktree(
|
|
|
788
844
|
|
|
789
845
|
shutil.copy2(src, dst)
|
|
790
846
|
|
|
791
|
-
|
|
792
|
-
|
|
847
|
+
# post-add hook
|
|
848
|
+
run_post_add_hook(worktree_path, work_name, base_dir, final_branch_name)
|
|
849
|
+
|
|
793
850
|
return worktree_path
|
|
794
851
|
else:
|
|
795
852
|
if result.stderr:
|
|
@@ -798,15 +855,29 @@ def add_worktree(
|
|
|
798
855
|
|
|
799
856
|
|
|
800
857
|
def cmd_add(args: list[str]):
|
|
801
|
-
"""wt add <work_name> [<base_branch>] - Add a worktree"""
|
|
858
|
+
"""wt add <work_name> [<base_branch>] [--skip-setup] - Add a worktree"""
|
|
802
859
|
if len(args) < 1:
|
|
803
860
|
print(msg("usage_add"), file=sys.stderr)
|
|
804
861
|
sys.exit(1)
|
|
805
862
|
|
|
806
|
-
|
|
807
|
-
|
|
863
|
+
# parse options
|
|
864
|
+
clean_args = []
|
|
865
|
+
skip_setup = False
|
|
866
|
+
|
|
867
|
+
for arg in args:
|
|
868
|
+
if arg == "--skip-setup":
|
|
869
|
+
skip_setup = True
|
|
870
|
+
else:
|
|
871
|
+
clean_args.append(arg)
|
|
872
|
+
|
|
873
|
+
if not clean_args:
|
|
874
|
+
print(msg("usage_add"), file=sys.stderr)
|
|
875
|
+
sys.exit(1)
|
|
808
876
|
|
|
809
|
-
|
|
877
|
+
work_name = clean_args[0]
|
|
878
|
+
branch_to_use = clean_args[1] if len(clean_args) >= 2 else None
|
|
879
|
+
|
|
880
|
+
add_worktree(work_name, branch_to_use=branch_to_use, skip_setup=skip_setup)
|
|
810
881
|
|
|
811
882
|
|
|
812
883
|
def cmd_stash(args: list[str]):
|
|
@@ -1344,7 +1415,8 @@ def cmd_select(args: list[str]):
|
|
|
1344
1415
|
sys.exit(1)
|
|
1345
1416
|
|
|
1346
1417
|
wt_dir = base_dir / ".wt"
|
|
1347
|
-
|
|
1418
|
+
# Ensure .wt directory and its management files (.gitignore etc) exist
|
|
1419
|
+
create_hook_template(base_dir)
|
|
1348
1420
|
last_sel_file = wt_dir / "last_selection"
|
|
1349
1421
|
|
|
1350
1422
|
# Get current selection name based on CWD or environment
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: easy-worktree
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Git worktree を簡単に管理するための CLI ツール
|
|
5
5
|
Project-URL: Homepage, https://github.com/igtm/easy-worktree
|
|
6
6
|
Project-URL: Repository, https://github.com/igtm/easy-worktree
|
|
@@ -107,6 +107,14 @@ You can also specify a base branch:
|
|
|
107
107
|
wt add feature-1 main
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
#### Skip Setup
|
|
111
|
+
|
|
112
|
+
If you want to create a worktree without running the automatic setup (file copy and hooks):
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
wt add feature-1 --skip-setup
|
|
116
|
+
```
|
|
117
|
+
|
|
110
118
|
#### List worktrees
|
|
111
119
|
|
|
112
120
|
```bash
|
|
@@ -235,9 +243,12 @@ Customize behavior in `.wt/config.toml`:
|
|
|
235
243
|
```toml
|
|
236
244
|
worktrees_dir = ".worktrees" # Directory where worktrees are created
|
|
237
245
|
setup_files = [".env"] # Files to auto-copy during setup
|
|
238
|
-
auto_copy_on_add = true # Enable auto-copy on worktree creation
|
|
239
246
|
```
|
|
240
247
|
|
|
248
|
+
#### Local Configuration Override
|
|
249
|
+
|
|
250
|
+
You can create `.wt/config.local.toml` to override settings locally. This file is automatically added to `.gitignore` and ignores `config.toml` settings.
|
|
251
|
+
|
|
241
252
|
## Hooks
|
|
242
253
|
|
|
243
254
|
You can define scripts to run automatically after `wt add`.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
easy_worktree/__init__.py,sha256=iK93RMds8Tpg_PO9fdO3o7qWb8krXFUOyocevfdvRfQ,64802
|
|
2
|
+
easy_worktree-0.1.4.dist-info/METADATA,sha256=_odaKmNmF_w4c-oULH4xghSSYCFfGy9vb_By_x7G8tU,6520
|
|
3
|
+
easy_worktree-0.1.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
4
|
+
easy_worktree-0.1.4.dist-info/entry_points.txt,sha256=Mf6MYDS2obZLvIJJFl-BbU8-SL0QGu5UWcC0FWnqtbg,42
|
|
5
|
+
easy_worktree-0.1.4.dist-info/licenses/LICENSE,sha256=7MGvWFDxXPqW2nrr9D7KHT0vWFiGwIUL5SQCj0IiAPc,1061
|
|
6
|
+
easy_worktree-0.1.4.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
easy_worktree/__init__.py,sha256=yHHZKyeljLEChIumw8ybGUmnvoCpoCJRBO_JE-l1Vmc,62539
|
|
2
|
-
easy_worktree-0.1.2.dist-info/METADATA,sha256=v4sCzlh43PBw0YPoNepc-orui3iobogZ_hKwyKep0Ug,6249
|
|
3
|
-
easy_worktree-0.1.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
4
|
-
easy_worktree-0.1.2.dist-info/entry_points.txt,sha256=Mf6MYDS2obZLvIJJFl-BbU8-SL0QGu5UWcC0FWnqtbg,42
|
|
5
|
-
easy_worktree-0.1.2.dist-info/licenses/LICENSE,sha256=7MGvWFDxXPqW2nrr9D7KHT0vWFiGwIUL5SQCj0IiAPc,1061
|
|
6
|
-
easy_worktree-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|