1# The code index is kept by the default branch's tree: a push that leaves2# that tree alone keeps the very same file, and a push that changes it3# rebuilds the index from the previous one, keeping unchanged files' rows.4. "$(dirname "$0")/../lib.sh"5user dami6repo dami/greet7clone dami dami/greet "$T/w/dami"8printf 'alpha one\n' >"$T/w/dami/a.txt"9printf 'beta two\n' >"$T/w/dami/b.txt"10at "$T/w/dami" commit "first"11push_as dami "$T/w/dami" origin main12build13db=$FORGE_WWW/dami/greet/code.db14inode() { ls -i "$1" | awk '{print $1}'; }15first=$(inode "$db")16# A review branch doesn't touch main's tree.17at "$T/w/dami" git switch -q -c dami/topic18at "$T/w/dami" commit "topic"19push_as dami "$T/w/dami" origin dami/topic20build21eq "$(inode "$db")" "$first"22# A new commit on main with the same tree (an empty commit) keeps it too.23at "$T/w/dami" git switch -q main24tick25at "$T/w/dami" git commit -q --allow-empty -m "empty"26push_as dami "$T/w/dami" origin main27build28eq "$(inode "$db")" "$first"29# Changing main rebuilds: the new text is found, the old is gone, and the30# unchanged file is still there.31printf 'alpha uno\n' >"$T/w/dami/a.txt"32at "$T/w/dami" commit "change" a.txt33push_as dami "$T/w/dami" origin main34build35[ "$(inode "$db")" != "$first" ] || fail "code.db was not rebuilt"36bench() { node "$T_HOME/test/code-search-bench.ts" sql "$db" "$1"; }37ok bench 'alpha uno'38eq "$(output)" 'a.txt:1: alpha uno'39ok bench 'alpha one'40eq "$(output)" ''41ok bench 'beta two'42eq "$(output)" 'b.txt:1: beta two'43# The cache keeps only the current index (and its layout).44eq "$(ls "$FORGE_CACHE/code/dami/greet" | wc -l | tr -d ' ')" 2