blob: 55422ec68df3374666dd4086695c1c968b3ea5f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
|