Skip to content

Commit 3d302be

Browse files
committed
wip
1 parent 1771d0b commit 3d302be

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

scripts/cleanup-worktree.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# ── Resolve the repo root from this script's location ────────────────────────
5+
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
6+
7+
# ── Usage ────────────────────────────────────────────────────────────────────
8+
if [[ $# -lt 1 ]]; then
9+
echo "Usage: $0 <worktree-path>"
10+
echo ""
11+
echo " Removes a worktree and cleans up its directory."
12+
echo ""
13+
echo "Examples:"
14+
echo " $0 ../alpine-fix-modal"
15+
echo " $0 /tmp/alpine-experiment"
16+
exit 1
17+
fi
18+
19+
DEST="$(cd "$(dirname "$1")" 2>/dev/null && pwd)/$(basename "$1")" || {
20+
DEST="$(pwd)/$1"
21+
}
22+
23+
# ── Validate ─────────────────────────────────────────────────────────────────
24+
if [[ ! -d "$DEST" ]]; then
25+
echo "Directory does not exist: $DEST"
26+
exit 1
27+
fi
28+
29+
# ── Remove ───────────────────────────────────────────────────────────────────
30+
echo "Removing worktree at $DEST..."
31+
git -C "$REPO_DIR" worktree remove --force "$DEST"
32+
33+
# ── Prune any stale worktree references ──────────────────────────────────────
34+
git -C "$REPO_DIR" worktree prune
35+
36+
echo ""
37+
echo "Worktree removed: $DEST"

scripts/worktree.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# ── Resolve the repo root from this script's location ────────────────────────
5+
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
6+
7+
# ── Usage ────────────────────────────────────────────────────────────────────
8+
if [[ $# -lt 1 ]]; then
9+
echo "Usage: $0 <destination> [branch]"
10+
echo ""
11+
echo " destination Path for the new worktree (relative or absolute)"
12+
echo " branch Optional branch/ref to base off (default: origin/main)"
13+
echo ""
14+
echo "Examples:"
15+
echo " $0 ../alpine-fix-modal"
16+
echo " $0 /tmp/alpine-experiment some-branch"
17+
exit 1
18+
fi
19+
20+
DEST="$(cd "$(dirname "$1")" 2>/dev/null && pwd)/$(basename "$1")" || {
21+
# Parent dir doesn't exist yet — resolve what we can
22+
DEST="$(pwd)/$1"
23+
}
24+
BASE="${2:-origin/main}"
25+
26+
# ── Check if it already exists ───────────────────────────────────────────────
27+
if [[ -d "$DEST" ]]; then
28+
echo "Worktree already exists at $DEST"
29+
echo ""
30+
echo " cd $DEST"
31+
exit 0
32+
fi
33+
34+
# ── Fetch & create ───────────────────────────────────────────────────────────
35+
echo "Fetching latest from origin..."
36+
git -C "$REPO_DIR" fetch origin
37+
38+
echo "Creating worktree at $DEST from $BASE..."
39+
git -C "$REPO_DIR" worktree add --detach "$DEST" "$BASE"
40+
41+
# ── Install deps ─────────────────────────────────────────────────────────────
42+
echo "Installing npm dependencies..."
43+
(cd "$DEST" && npm install --silent 2>&1) || {
44+
echo " WARNING: npm install failed"
45+
}
46+
47+
# ── Done ─────────────────────────────────────────────────────────────────────
48+
echo ""
49+
echo "════════════════════════════════════════"
50+
echo " Worktree ready!"
51+
echo ""
52+
echo " cd $DEST"
53+
echo "════════════════════════════════════════"

0 commit comments

Comments
 (0)