44#
55# scripts/dev-worktree.sh add <branch> [worktree-dir]
66# scripts/dev-worktree.sh remove <worktree-dir>
7+ # scripts/dev-worktree.sh workspace # regen pyconkr.code-workspace
78#
89# Reads envfile/.env.local for Postgres credentials; the new worktree
910# gets a copy with only DATABASE_NAME rewritten.
@@ -12,6 +13,7 @@ set -euo pipefail
1213REPO_ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /.." && pwd) "
1314ENV_REL=" envfile/.env.local"
1415SRC_ENV=" $REPO_ROOT /$ENV_REL "
16+ WORKSPACE_FILE=" $REPO_ROOT /pyconkr.code-workspace"
1517
1618usage () {
1719 awk ' NR>1 && /^[^#]/ {exit} NR>1 {sub(/^# ?/, ""); print}' " $0 "
@@ -49,6 +51,37 @@ sanitize() {
4951 | sed -E ' s/[^a-z0-9]+/_/g; s/^_+|_+$//g'
5052}
5153
54+ # Regenerate the multi-root workspace so each .worktrees/<slug> is its own root
55+ # (with its own Source Control) next to the main repo. .worktrees is hidden in
56+ # the main root to avoid showing every worktree twice.
57+ regen_workspace () {
58+ local folders=' { "name": "backend (main)", "path": "." }'
59+ local d slug
60+ for d in " $REPO_ROOT " /.worktrees/* /; do
61+ [ -d " $d " ] || continue
62+ slug=$( basename " $d " )
63+ folders+=$' ,\n ' " { \" name\" : \" wt: $slug \" , \" path\" : \" .worktrees/$slug \" }"
64+ done
65+ cat > " $WORKSPACE_FILE " << EOF
66+ {
67+ "folders": [
68+ $folders
69+ ],
70+ "settings": {
71+ "files.exclude": { "**/.worktrees": true }
72+ }
73+ }
74+ EOF
75+ echo " synced ${WORKSPACE_FILE##*/ } (VSCode: File → Open Workspace from File…)"
76+ }
77+
78+ # Auto-refresh only for devs who opted in by creating the file once
79+ # (`make local-worktree-sync`). Non-VSCode users never get the file.
80+ sync_workspace_if_present () {
81+ [ -f " $WORKSPACE_FILE " ] || return 0
82+ regen_workspace
83+ }
84+
5285cmd_add () {
5386 local branch=" ${1:- } " ; [ -n " $branch " ] || usage 1
5487 local slug; slug=$( sanitize " $branch " )
@@ -102,6 +135,8 @@ cmd_add() {
102135 exit 1
103136 fi
104137
138+ sync_workspace_if_present
139+
105140 cat << EOF
106141
107142next:
@@ -135,13 +170,16 @@ cmd_remove() {
135170 # DATABASE_NAME on add, and the tree may contain .venv/__pycache__/coverage
136171 # artifacts. The y/N prompt above is the safety gate.
137172 git -C " $REPO_ROOT " worktree remove --force " $wt_dir "
173+
174+ sync_workspace_if_present
138175}
139176
140177main () {
141178 local sub=" ${1:- } " ; shift || true
142179 case " $sub " in
143180 add) cmd_add " $@ " ;;
144181 remove|rm) cmd_remove " $@ " ;;
182+ workspace|ws|sync) regen_workspace ;;
145183 -h|--help|" " ) usage 0 ;;
146184 * ) usage 1 ;;
147185 esac
0 commit comments