Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions post-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ is_luca_installed() {
command -v luca >/dev/null 2>&1
}

# Check if installed luca version matches .luca-version file
is_luca_version_correct() {
if [ ! -f "$VERSION_FILE" ]; then
return 0 # no version file, nothing to check
fi
REQUIRED_VERSION=$(cat "$VERSION_FILE")
INSTALLED_VERSION=$(luca --version 2>/dev/null)
[ "$INSTALLED_VERSION" = "$REQUIRED_VERSION" ]
}

# =============================================================================
# MAIN HOOK LOGIC
# =============================================================================
Expand All @@ -95,6 +105,7 @@ if [ -z "$REPO_ROOT" ]; then
exit 0
fi

VERSION_FILE="$REPO_ROOT/.luca-version"
LUCAFILE_PATH="$REPO_ROOT/$LUCAFILE"

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

# Check if Luca is installed, install if not
if ! is_luca_installed; then
log_info "Luca not found, installing..."

# Check if Luca is installed and version is correct, install/update if not
if ! is_luca_installed || ! is_luca_version_correct; then
if ! is_luca_installed; then
log_info "Luca not found, installing..."
else
REQUIRED=$(cat "$VERSION_FILE")
INSTALLED=$(luca --version 2>/dev/null)
log_info "Luca version mismatch (installed: $INSTALLED, required: $REQUIRED), updating..."
fi

if command -v curl >/dev/null 2>&1; then
/bin/bash -c "$(curl -fsSL $INSTALL_SCRIPT_URL)"
INSTALL_RESULT=$?

if [ $INSTALL_RESULT -ne 0 ]; then
log_error "Failed to install Luca"
exit 1
fi

log_success "Luca installed"
else
log_error "curl is required to install Luca"
Expand Down
36 changes: 36 additions & 0 deletions tests/post_checkout.bats
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,39 @@ setup() {
assert_success
assert_output --partial "Some tools may have failed"
}

# ---------------------------------------------------------------------------
# Luca version check
# ---------------------------------------------------------------------------

@test "version check: luca version matches .luca-version, curl NOT called to reinstall" {
cp "$FIXTURE_DIR/Lucafile" "$FAKE_REPO/Lucafile"
echo "v1.0.0" > "$FAKE_REPO/.luca-version" # matches MOCK_LUCA_VERSION default

run "$REPO_ROOT/post-checkout" prev_ref new_ref 1

assert_success
refute_output --partial "mismatch"
refute_output --partial "installing"
}

@test "version check: luca version mismatch triggers reinstall with mismatch message" {
cp "$FIXTURE_DIR/Lucafile" "$FAKE_REPO/Lucafile"
echo "v2.0.0" > "$FAKE_REPO/.luca-version" # differs from MOCK_LUCA_VERSION (v1.0.0)

run "$REPO_ROOT/post-checkout" prev_ref new_ref 1

assert_output --partial "version mismatch"
assert_output --partial "v1.0.0"
assert_output --partial "v2.0.0"
}

@test "version check: no .luca-version file skips version check" {
cp "$FIXTURE_DIR/Lucafile" "$FAKE_REPO/Lucafile"
# No .luca-version file created

run "$REPO_ROOT/post-checkout" prev_ref new_ref 1

assert_success
refute_output --partial "mismatch"
}
4 changes: 2 additions & 2 deletions tests/shell_hook.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ setup() {
source '$REPO_ROOT/shell_hook.sh' >/dev/null 2>&1
update_path
update_path
# Count occurrences of the tools dir in PATH
echo \"\$PATH\" | tr ':' '\n' | grep -c '\.luca/tools' || echo 0
# Count occurrences of the specific tools dir in PATH
echo \"\$PATH\" | tr ':' '\n' | grep -cxF '$project/.luca/tools' || echo 0
"

assert_output "1"
Expand Down
Loading