Skip to content

Commit 742b8ee

Browse files
committed
chore: VSCode에서 worktree가 잘 보이도록 수정
1 parent e47605f commit 742b8ee

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ media/*
255255

256256
# Git worktrees (scripts/dev-worktree.sh creates .worktrees/<slug> in-repo)
257257
.worktrees/
258+
# Auto-generated multi-root workspace listing the local worktrees (per-dev)
259+
pyconkr.code-workspace
258260

259261
# Jupyter Notebook
260262
.ipynb_checkpoints

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ local-worktree-remove:
103103
@$(if $(dir),,$(error dir=<worktree-path> is required))
104104
@./scripts/dev-worktree.sh remove "$(dir)"
105105

106+
# Regenerate pyconkr.code-workspace (main repo + every .worktrees/<slug> as roots)
107+
local-worktree-sync:
108+
@./scripts/dev-worktree.sh workspace
109+
106110

107111
# Devtools
108112
hooks-install: local-setup

scripts/dev-worktree.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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
1213
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
1314
ENV_REL="envfile/.env.local"
1415
SRC_ENV="$REPO_ROOT/$ENV_REL"
16+
WORKSPACE_FILE="$REPO_ROOT/pyconkr.code-workspace"
1517

1618
usage() {
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+
5285
cmd_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
107142
next:
@@ -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

140177
main() {
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

Comments
 (0)