From 4834f0ad9d5fa4179c9fae894a79e7085f4b868c Mon Sep 17 00:00:00 2001 From: Oskar Kapala Date: Tue, 5 May 2026 15:55:18 +0200 Subject: [PATCH] add safe context sync script --- sync-context.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 sync-context.sh diff --git a/sync-context.sh b/sync-context.sh new file mode 100755 index 0000000..1d27956 --- /dev/null +++ b/sync-context.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -euo pipefail + +REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)" + +if [[ -z "$REPO_ROOT" ]]; then + echo "Not inside a git repository" >&2 + exit 1 +fi + +if [[ "$(pwd)" != "$REPO_ROOT" ]]; then + echo "Run this script from the repo root" >&2 + exit 1 +fi + +mapfile -t status_lines < <(git status --porcelain=v1 --untracked-files=all) + +for line in "${status_lines[@]}"; do + path="${line:3}" + if [[ "$path" != "codex_context.yaml" ]]; then + echo "Refusing to sync: only codex_context.yaml may be changed" >&2 + exit 1 + fi +done + +git pull --rebase + +if git diff --quiet -- codex_context.yaml && git diff --cached --quiet -- codex_context.yaml; then + echo "No context changes to sync" + exit 0 +fi + +python3 -c "import yaml; yaml.safe_load(open('codex_context.yaml'))" +git add codex_context.yaml +git commit -m "update shared context" +git push