Skip to content

Commit 65b89d8

Browse files
committed
fix: worktree 생성 / 삭제 스크립트가 worktree 정리 시 --force를 사용해야 하던 문제 수정
1 parent e9f0529 commit 65b89d8

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

scripts/dev-worktree.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,25 @@ cmd_add() {
5555
local wt_dir="${2:-$REPO_ROOT/../backend-$slug}"
5656

5757
load_db_env "$SRC_ENV"
58-
local new_db="${DB_NAME}__${slug}"
59-
[ "${#new_db}" -le 63 ] || die "db name '$new_db' exceeds PG 63-char limit"
58+
# PG identifier limit is 63 chars; pytest-django auto-creates test_<dbname>,
59+
# so reserve 5 more for that prefix.
60+
local db_prefix="${DB_NAME}__"
61+
local max_db_slug=$((63 - 5 - ${#db_prefix}))
62+
[ "$max_db_slug" -ge 10 ] \
63+
|| die "DATABASE_NAME '$DB_NAME' leaves <10 chars for a worktree slug"
64+
local db_slug="$slug"
65+
if [ "${#db_slug}" -gt "$max_db_slug" ]; then
66+
local hash; hash=$(printf '%s' "$branch" | shasum | cut -c1-6)
67+
db_slug="${db_slug:0:$((max_db_slug - 7))}_${hash}"
68+
fi
69+
local new_db="${db_prefix}${db_slug}"
6070
[ "$new_db" != "$DB_NAME" ] || die "computed db name collides with source"
6171

6272
echo "→ worktree dir : $wt_dir"
6373
echo "→ branch : $branch"
6474
echo "→ database : $new_db"
75+
[ "$db_slug" = "$slug" ] \
76+
|| echo " (slug truncated for PG 63-char limit: $slug$db_slug)"
6577

6678
if [ -d "$wt_dir" ]; then
6779
echo " worktree dir already exists — skipping git worktree add"
@@ -119,7 +131,10 @@ cmd_remove() {
119131

120132
pg dropdb --if-exists "$DB_NAME"
121133
pg dropdb --if-exists "test_$DB_NAME"
122-
git -C "$REPO_ROOT" worktree remove "$wt_dir"
134+
# --force: envfile/.env.local is tracked but rewritten with a per-worktree
135+
# DATABASE_NAME on add, and the tree may contain .venv/__pycache__/coverage
136+
# artifacts. The y/N prompt above is the safety gate.
137+
git -C "$REPO_ROOT" worktree remove --force "$wt_dir"
123138
}
124139

125140
main() {

0 commit comments

Comments
 (0)