-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-worktree
More file actions
executable file
·135 lines (112 loc) · 4.08 KB
/
make-worktree
File metadata and controls
executable file
·135 lines (112 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
set -e # Exit on error
# Check if branch name is provided
if [ -z "$1" ]; then
echo -e "${RED}Error: Branch name is required${NC}"
echo -e "${YELLOW}Usage: ./make-worktree <branch-name>${NC}"
echo -e "${YELLOW}Example: ./make-worktree feat/ogn-tracker-type${NC}"
exit 1
fi
BRANCH_NAME="$1"
WORKTREE_DIR="$HOME/soar-worktrees/$BRANCH_NAME"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check for .env file
ENV_FILE=""
if [ -f ".env" ]; then
ENV_FILE=".env"
elif [ -f "$HOME/soar/.env" ]; then
ENV_FILE="$HOME/soar/.env"
else
echo -e "${RED}Error: .env file not found in current directory or $HOME/soar/.env${NC}"
exit 1
fi
echo -e "${BOLD}${CYAN}Creating worktree for branch: ${MAGENTA}$BRANCH_NAME${NC}"
echo -e "${CYAN}Location: ${NC}$WORKTREE_DIR"
echo ""
# Create the worktree
echo -e "${BLUE}[1/3]${NC} ${BOLD}Creating git worktree...${NC}"
git worktree add -b "$BRANCH_NAME" "$WORKTREE_DIR" main
echo -e "${GREEN}✓ Worktree created${NC}"
echo ""
# Copy .env file
echo -e "${BLUE}[2/3]${NC} ${BOLD}Copying .env file...${NC}"
cp "$ENV_FILE" "$WORKTREE_DIR/.env"
echo -e "${GREEN}✓ .env file copied${NC}"
echo ""
# Launch background builds
echo -e "${BLUE}[3/3]${NC} ${BOLD}Launching background builds...${NC}"
mkdir -p "$WORKTREE_DIR/.logs"
# Background bun install
(
cd "$WORKTREE_DIR/web"
bun install &>"$WORKTREE_DIR/.logs/bun-install.log"
echo -e "${GREEN}✓ bun dependencies installed${NC}" >> "$WORKTREE_DIR/.logs/bun-install.log"
) &
BUN_PID=$!
# Check for sccache and warn if not installed
if command -v sccache &>/dev/null; then
SCCACHE_PATH=$(command -v sccache)
echo -e "${GREEN}✓ sccache found: ${CYAN}$SCCACHE_PATH${NC}"
else
echo -e "${YELLOW}⚠ Warning: sccache not installed - builds will be slower without caching${NC}"
echo -e "${YELLOW} Install with: ${CYAN}cargo install sccache${NC}"
SCCACHE_PATH=""
fi
# Background cargo build (dependencies only)
# We use 'cargo check' which is faster than 'cargo build' and still compiles all dependencies
# This populates sccache without building the final soar binary
(
cd "$WORKTREE_DIR"
# Set RUSTC_WRAPPER for sccache if available
if [ -n "$SCCACHE_PATH" ]; then
export RUSTC_WRAPPER="$SCCACHE_PATH"
fi
# First, fetch all dependencies
cargo fetch &>"$WORKTREE_DIR/.logs/cargo-fetch.log"
# Then check all dependencies (faster than build, still caches everything)
cargo check --all-targets --all-features &>"$WORKTREE_DIR/.logs/cargo-check.log"
echo -e "${GREEN}✓ Cargo dependencies cached${NC}" >> "$WORKTREE_DIR/.logs/cargo-check.log"
) &
CARGO_PID=$!
echo -e "${CYAN} • bun install running in background (PID: $BUN_PID)${NC}"
echo -e "${CYAN} • cargo check running in background (PID: $CARGO_PID)${NC}"
echo -e "${CYAN} • Logs: $WORKTREE_DIR/.logs/${NC}"
echo -e "${GREEN}✓ Background builds started${NC}"
echo ""
echo -e "${GREEN}${BOLD}✓ Worktree setup complete!${NC}"
echo -e "${YELLOW}Background builds are still running. Check progress with:${NC}"
echo -e "${CYAN} tail -f $WORKTREE_DIR/.logs/bun-install.log${NC}"
echo -e "${CYAN} tail -f $WORKTREE_DIR/.logs/cargo-check.log${NC}"
echo ""
# Change to the worktree directory
cd "$WORKTREE_DIR"
# Run mise trust if mise is installed
if command -v mise &> /dev/null; then
echo -e "${BLUE}Running mise trust...${NC}"
mise trust 2>/dev/null || true
echo -e "${GREEN}✓ mise trust complete${NC}"
fi
# Set tmux window title if in tmux
if [ -n "$TMUX" ]; then
tmux rename-window "$BRANCH_NAME" 2>/dev/null || true
echo -e "${GREEN}✓ tmux window renamed to: ${MAGENTA}$BRANCH_NAME${NC}"
fi
echo ""
echo -e "${BOLD}${CYAN}Launching Claude Code...${NC}"
echo ""
# Launch Claude Code in the worktree directory
if command -v claude &> /dev/null; then
claude
else
echo -e "${YELLOW}Warning: 'claude' command not found${NC}"
echo -e "${CYAN}Worktree is ready at: $(pwd)${NC}"
fi