Files
zeekay 10e6fec4c0 debrand: the brand token is INSIGHTS_, and a wrong one stops the container
The rule table mapped HOG_ -> FN_ ahead of any POSTHOG rule, so POSTHOG_FOO
split into POST + HOG_ and came out POSTFN_FOO. Nothing sets that. The live
pods set INSIGHTS_SKIP_MIGRATION_CHECKS, which bin/migrate-check reads on the
container entrypoint, so the misspelling does not degrade a feature -- it runs
migrate --check against a database whose history this tree does not share and
the container never starts.

Both replacements are measured against the shipped tree rather than chosen:
every HOG_ name with a counterpart there is spelled INSIGHTS_ (HOG_QL ->
INSIGHTS_QL, HOG_FUNCTION_TEMPLATES -> INSIGHTS_FUNCTION_TEMPLATES, 12 of 12
determinate cases), and FN_ appears in it nowhere. Upstream carries 95 HOG_
tokens and zero FN_ ones, so repairing FN_ back out is exactly the inverse of
the bad rule and cannot collide with an upstream name.

The rule is fixed for the next convergence, and the tree it already produced is
repaired in the same commit -- the codemod is idempotent against its own output,
so it cannot undo this itself.
2026-08-01 17:42:28 -07:00

194 lines
6.6 KiB
Bash

#!/bin/bash
# Insights Worktree wrapper function installer
# Source this file in your shell profile to use the phw function
# phw is sourced from the flox activate hook, so $FLOX_ENV_PROJECT points
# to the repo root that owns this script.
source "$FLOX_ENV_PROJECT/bin/helpers/_utils.sh" 2>/dev/null || {
# Fallback error function if utils not available
error() { echo "Error: $*" >&2; }
fatal() { error "$*"; return 1; }
}
# Helper function to find worktree path by branch name
_find_worktree_path() {
git worktree list 2>/dev/null | grep -E "\[$1\]$" | awk '{print $1}'
}
# Helper function to clean environment variables before entering worktree
_clean_environment() {
unset VIRTUAL_ENV PYTHONPATH CONDA_DEFAULT_ENV 2>/dev/null || true
}
# Helper function to activate Flox environment
_activate_flox() {
if ! command -v direnv &>/dev/null; then
echo "Activating Flox environment via .envrc…"
source .envrc
fi
# If direnv is set up, it will auto-activate via .envrc
}
# Helper function to switch to worktree directory
_switch_to_worktree() {
local worktree_path="$1"
local branch_name="$2"
if [[ -d "$worktree_path" ]]; then
echo "Switching to worktree directory…"
_clean_environment
cd "$worktree_path"
_activate_flox
else
error "Worktree directory not found: $worktree_path"
return 1
fi
}
phw() {
local script_path="$FLOX_ENV_PROJECT/bin/insights-worktree"
local command="$1"
local branch="$2"
# Handle switch command directly (doesn't need main script)
if [[ "$command" == "switch" ]]; then
if [[ -z "$branch" ]]; then
error "Branch name required"
echo "Usage: phw switch <branch-name>"
return 1
fi
local worktree_path=$(_find_worktree_path "$branch")
if [[ -z "$worktree_path" ]]; then
error "No worktree found for branch '$branch'"
echo "Available worktrees:"
git worktree list
return 1
fi
if [[ ! -d "$worktree_path" ]]; then
error "Worktree directory does not exist: $worktree_path"
return 1
fi
echo "Switching to worktree: $branch"
echo "Location: $worktree_path"
# Add to shell history for convenience
if command -v history >/dev/null 2>&1; then
history -s "cd \"$worktree_path\""
fi
_switch_to_worktree "$worktree_path" "$branch"
return 0
fi
# Run the actual script for other commands
"$script_path" "$@"
# Auto-cd to worktree after successful command execution
if [[ -n "$branch" ]]; then
local worktree_base="${INSIGHTS_WORKTREE_BASE:-$HOME/.worktrees/insights}"
local worktree_path=""
case "$command" in
create|checkout|start)
worktree_path="$worktree_base/$branch"
;;
pr)
# For PR, find the directory by pattern (pr-NUMBER-author)
worktree_path=$(find "$worktree_base" -maxdepth 1 -type d -name "pr-${branch}-*" 2>/dev/null | head -n1)
;;
esac
if [[ -n "$worktree_path" ]] && [[ -d "$worktree_path" ]]; then
_switch_to_worktree "$worktree_path" "$branch"
fi
fi
}
# Add completion support for bash and zsh
if [ -n "$BASH_VERSION" ]; then
_phw_completions() {
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=($(compgen -W "create checkout pr remove list switch" -- "$cur"))
elif [[ $COMP_CWORD -eq 2 ]]; then
case "$prev" in
remove|switch)
# Complete with existing worktree branch names
local worktrees=$(git worktree list 2>/dev/null | sed -n 's/.*\[\(.*\)\].*/\1/p' | grep -v '^$')
COMPREPLY=($(compgen -W "$worktrees" -- "$cur"))
;;
checkout)
# Complete with branch names
local branches=$(git branch -a 2>/dev/null | grep -v HEAD | sed 's/^[* ]*//' | sed 's/remotes\/origin\///' | sort -u)
COMPREPLY=($(compgen -W "$branches" -- "$cur"))
;;
pr)
# No completion for PR numbers
;;
create)
# Suggest branch name format
COMPREPLY=($(compgen -W "haacked/" -- "$cur"))
;;
esac
fi
}
complete -F _phw_completions phw
elif [ -n "$ZSH_VERSION" ]; then
# Advanced zsh completion function
_phw_complete() {
local -a commands
local context state line
commands=(
'create:Create a new worktree for a branch'
'checkout:Checkout existing branch in a worktree'
'pr:Checkout a PR in a worktree'
'remove:Remove a worktree'
'list:List all worktrees'
'switch:Switch to existing worktree'
)
case $CURRENT in
2)
_describe 'commands' commands
;;
3)
case $words[2] in
remove|switch)
# Complete with existing worktree branch names
local -a worktrees
worktrees=($(git worktree list 2>/dev/null | sed -n 's/.*\[\(.*\)\].*/\1/p' | grep -v '^$' 2>/dev/null))
if [[ ${#worktrees[@]} -gt 0 ]]; then
_describe 'worktrees' worktrees
fi
;;
checkout)
# Complete with branch names
local -a branches
branches=($(git branch -a 2>/dev/null | grep -v HEAD | sed 's/^[* ]*//' | sed 's/remotes\/origin\///' | sort -u 2>/dev/null))
if [[ ${#branches[@]} -gt 0 ]]; then
_describe 'branches' branches
fi
;;
esac
;;
esac
}
# Use compdef to register the completion function
if command -v compdef >/dev/null 2>&1; then
compdef _phw_complete phw
else
# Fallback to simple completion if compdef not available
compctl -k '(create checkout pr remove list)' phw
fi
fi
echo "Insights worktree helper loaded. Use 'phw' command."