diff --git a/tools/apply_xiao_sensor_node_patch.sh b/tools/apply_xiao_sensor_node_patch.sh new file mode 100755 index 0000000..1533b44 --- /dev/null +++ b/tools/apply_xiao_sensor_node_patch.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -euo pipefail + +PATCH_COMMIT="a701059" + +repo_root="$(git rev-parse --show-toplevel)" +cd "$repo_root" + +if [[ -n "$(git status --porcelain)" ]]; then + echo "Refusing to edit a dirty working tree." >&2 + exit 1 +fi + +if ! git cat-file -e "${PATCH_COMMIT}^{commit}" 2>/dev/null; then + git fetch origin +fi + +if ! git merge-base --is-ancestor "$PATCH_COMMIT" HEAD; then + git cherry-pick "$PATCH_COMMIT" +else + echo "XIAO sensor-node patch is already applied." +fi + +if [[ ! -f .venv/bin/activate ]]; then + echo "Missing .venv/bin/activate; create the project virtual environment first." >&2 + exit 1 +fi + +source .venv/bin/activate +python run_tests.py + +git add -A +if ! git diff --cached --quiet; then + git commit -m "firmware: apply XIAO C6 sensor node patch" +fi + +branch="$(git branch --show-current)" +if [[ -z "$branch" ]]; then + echo "Cannot push from detached HEAD." >&2 + exit 1 +fi +git push origin "$branch"