Skip to content

Commit 3244acf

Browse files
Merge pull request #8 from LucaTools/install-luca-in-post-checkout
Add version check in post-checkout hook
2 parents fdb756b + cb5b0d9 commit 3244acf

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

post-checkout

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ is_luca_installed() {
6969
command -v luca >/dev/null 2>&1
7070
}
7171

72+
# Check if installed luca version matches .luca-version file
73+
is_luca_version_correct() {
74+
if [ ! -f "$VERSION_FILE" ]; then
75+
return 0 # no version file, nothing to check
76+
fi
77+
REQUIRED_VERSION=$(cat "$VERSION_FILE")
78+
INSTALLED_VERSION=$(luca --version 2>/dev/null)
79+
[ "$INSTALLED_VERSION" = "$REQUIRED_VERSION" ]
80+
}
81+
7282
# =============================================================================
7383
# MAIN HOOK LOGIC
7484
# =============================================================================
@@ -95,6 +105,7 @@ if [ -z "$REPO_ROOT" ]; then
95105
exit 0
96106
fi
97107

108+
VERSION_FILE="$REPO_ROOT/.luca-version"
98109
LUCAFILE_PATH="$REPO_ROOT/$LUCAFILE"
99110

100111
# Only proceed if Lucafile exists
@@ -109,19 +120,25 @@ log_info "Found $LUCAFILE, synchronizing tools..."
109120
# LUCA INSTALLATION CHECK
110121
# =============================================================================
111122

112-
# Check if Luca is installed, install if not
113-
if ! is_luca_installed; then
114-
log_info "Luca not found, installing..."
115-
123+
# Check if Luca is installed and version is correct, install/update if not
124+
if ! is_luca_installed || ! is_luca_version_correct; then
125+
if ! is_luca_installed; then
126+
log_info "Luca not found, installing..."
127+
else
128+
REQUIRED=$(cat "$VERSION_FILE")
129+
INSTALLED=$(luca --version 2>/dev/null)
130+
log_info "Luca version mismatch (installed: $INSTALLED, required: $REQUIRED), updating..."
131+
fi
132+
116133
if command -v curl >/dev/null 2>&1; then
117134
/bin/bash -c "$(curl -fsSL $INSTALL_SCRIPT_URL)"
118135
INSTALL_RESULT=$?
119-
136+
120137
if [ $INSTALL_RESULT -ne 0 ]; then
121138
log_error "Failed to install Luca"
122139
exit 1
123140
fi
124-
141+
125142
log_success "Luca installed"
126143
else
127144
log_error "curl is required to install Luca"

tests/post_checkout.bats

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,39 @@ setup() {
126126
assert_success
127127
assert_output --partial "Some tools may have failed"
128128
}
129+
130+
# ---------------------------------------------------------------------------
131+
# Luca version check
132+
# ---------------------------------------------------------------------------
133+
134+
@test "version check: luca version matches .luca-version, curl NOT called to reinstall" {
135+
cp "$FIXTURE_DIR/Lucafile" "$FAKE_REPO/Lucafile"
136+
echo "v1.0.0" > "$FAKE_REPO/.luca-version" # matches MOCK_LUCA_VERSION default
137+
138+
run "$REPO_ROOT/post-checkout" prev_ref new_ref 1
139+
140+
assert_success
141+
refute_output --partial "mismatch"
142+
refute_output --partial "installing"
143+
}
144+
145+
@test "version check: luca version mismatch triggers reinstall with mismatch message" {
146+
cp "$FIXTURE_DIR/Lucafile" "$FAKE_REPO/Lucafile"
147+
echo "v2.0.0" > "$FAKE_REPO/.luca-version" # differs from MOCK_LUCA_VERSION (v1.0.0)
148+
149+
run "$REPO_ROOT/post-checkout" prev_ref new_ref 1
150+
151+
assert_output --partial "version mismatch"
152+
assert_output --partial "v1.0.0"
153+
assert_output --partial "v2.0.0"
154+
}
155+
156+
@test "version check: no .luca-version file skips version check" {
157+
cp "$FIXTURE_DIR/Lucafile" "$FAKE_REPO/Lucafile"
158+
# No .luca-version file created
159+
160+
run "$REPO_ROOT/post-checkout" prev_ref new_ref 1
161+
162+
assert_success
163+
refute_output --partial "mismatch"
164+
}

tests/shell_hook.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ setup() {
3939
source '$REPO_ROOT/shell_hook.sh' >/dev/null 2>&1
4040
update_path
4141
update_path
42-
# Count occurrences of the tools dir in PATH
43-
echo \"\$PATH\" | tr ':' '\n' | grep -c '\.luca/tools' || echo 0
42+
# Count occurrences of the specific tools dir in PATH
43+
echo \"\$PATH\" | tr ':' '\n' | grep -cxF '$project/.luca/tools' || echo 0
4444
"
4545

4646
assert_output "1"

0 commit comments

Comments
 (0)