aboutsummaryrefslogtreecommitdiff
path: root/scripts/roam-sync.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/roam-sync.sh')
-rwxr-xr-xscripts/roam-sync.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/roam-sync.sh b/scripts/roam-sync.sh
new file mode 100755
index 0000000..55422ec
--- /dev/null
+++ b/scripts/roam-sync.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+# roam-sync.sh — git auto-sync for the org-roam knowledge base (spec D8).
+#
+# Commit any local changes, rebase onto the remote, push. Run by the
+# roam-sync systemd user timer (scripts/systemd/) every 15 minutes so
+# Craig's hand edits travel without a manual git step. Agents don't need
+# this — they pull/commit/push inline per claude-rules/knowledge-base.md.
+#
+# On a rebase conflict: abort the rebase (never leave the repo mid-rebase
+# for a timer to mangle), keep the local commit, exit 1 so the failure is
+# visible in `systemctl --user status roam-sync`.
+#
+# Usage: roam-sync.sh [repo-path] (default ~/org/roam)
+
+set -euo pipefail
+
+repo="${1:-$HOME/org/roam}"
+
+if ! git -C "$repo" rev-parse --git-dir >/dev/null 2>&1; then
+ echo "roam-sync: $repo is not a git repo" >&2
+ exit 1
+fi
+
+cd "$repo"
+
+# Commit local changes first so the rebase replays them.
+if [ -n "$(git status --porcelain)" ]; then
+ git add -A
+ git commit -qm "chore: auto-sync $(date '+%Y-%m-%d %H:%M %z')"
+fi
+
+if ! git pull --rebase -q 2>&1; then
+ git rebase --abort 2>/dev/null || true
+ echo "roam-sync: rebase conflict in $repo — local commit kept, resolve by hand" >&2
+ exit 1
+fi
+
+git push -q