-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_flutter.template.sh
More file actions
executable file
·110 lines (92 loc) · 3.11 KB
/
setup_flutter.template.sh
File metadata and controls
executable file
·110 lines (92 loc) · 3.11 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
#!/bin/bash
set -e
# --- Configuration ---
# Check if ORIGIN_URL is provided (e.g. via environment variable)
# If not, prompt the user interactively.
if [ -z "$ORIGIN_URL" ]; then
echo "Don't have a fork yet? https://github.com/flutter/flutter/fork"
echo "Please enter your Flutter fork URL (e.g. git@github.com:username/flutter.git)"
read -r -p "Origin URL: " ORIGIN_URL
fi
if [ -z "$ORIGIN_URL" ]; then
echo "❌ Error: Origin URL is required. Aborting."
exit 1
fi
UPSTREAM_URL="https://github.com/flutter/flutter.git"
# Specific refs
REF_STABLE="stable"
# echo "🚀 Starting Flutter Worktree Setup..."
# 1. Create root directory
if [ -d "flutter" ]; then
echo "❌ Error: Directory 'flutter' already exists. Aborting."
exit 1
fi
mkdir -p "flutter"
cd "flutter"
ROOT_PATH=$(pwd)
# 2. Clone Bare Repo
echo "📦 Cloning origin as bare repository..."
echo " Origin: '$OriginUrl'"
git clone --bare "$ORIGIN_URL" .bare
echo "gitdir: ./.bare" > .git
# 3. Configure Remotes
echo "⚙️ Configuring remotes..."
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git remote add upstream "$UPSTREAM_URL"
git config remote.upstream.fetch "+refs/heads/*:refs/remotes/upstream/*"
# 4. Fetch tags / branches
echo "⬇️ Fetching everything (--all --tags --prune)..."
git fetch --all --tags --prune
# --- Setup MASTER ---
echo "🌲 Creating 'master' worktree (tracking upstream/master)..."
git worktree add -B master master --track upstream/master
# --- Setup STABLE ---
if [ -z "$SETUP_STABLE" ]; then
read -p "Do you want to setup the 'stable' worktree? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
SETUP_STABLE=true
else
SETUP_STABLE=false
fi
fi
if [ "$SETUP_STABLE" = true ] || [[ "$SETUP_STABLE" =~ ^[Yy] ]]; then
SETUP_STABLE=true
echo "🌲 Creating 'stable' worktree (based on upstream/$REF_STABLE)..."
# We create a local branch named 'stable' based on the upstream ref
git worktree add -B stable stable --track upstream/"$REF_STABLE"
else
SETUP_STABLE=false
fi
# 5. Pre-load Artifacts
# We run --version to download the engine/dart-sdk for both immediately
if [ "$SETUP_STABLE" = true ]; then
echo "🛠️ Hydrating 'stable' artifacts..."
cd stable
./bin/flutter --version > /dev/null
cd ..
fi
echo "🛠️ Hydrating 'master' artifacts..."
cd master
./bin/flutter --version > /dev/null
cd ..
# 6. Generate The Switcher Script
echo "🔗 Generating context switcher..."
SWITCH_FILE="$ROOT_PATH/fswitch.sh"
PAYLOAD="REPLACE_ME"
echo "$PAYLOAD" | base64 --decode > "$SWITCH_FILE"
chmod +x "$SWITCH_FILE"
echo ""
echo "✅ Setup Complete!"
echo "------------------------------------------------------"
echo "📂 Root: $ROOT_PATH"
echo "👉 To enable the switcher, add this to your .zshrc / .bashrc:"
echo " source $SWITCH_FILE > /dev/null 2>&1"
echo ""
echo "Usage:"
echo " $ fswitch master -> Activates master branch"
echo " $ fswitch stable -> Activates stable branch"
echo ""
echo "Want to create a new worktree?"
echo " $ git worktree add my_feature"
echo "------------------------------------------------------"