-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeads-sync
More file actions
executable file
·71 lines (59 loc) · 1.7 KB
/
Copy pathbeads-sync
File metadata and controls
executable file
·71 lines (59 loc) · 1.7 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -euo pipefail
# Sync beads issues to a central beads-sync repository, with one
# subdirectory per project (named after the origin remote's repo name).
#
# Local clone lives at ~/.local/share/beads-sync/.
BEADS_DIR=".beads"
SYNC_REPO="$HOME/.local/share/beads-sync"
REMOTE_REPO="git@github.com:MichaelSims/beads-sync.git"
if [ ! -d "$BEADS_DIR" ]; then
echo "error: no $BEADS_DIR directory in $(pwd)" >&2
exit 1
fi
# Derive project name from origin remote
ORIGIN_URL=$(git remote get-url origin 2>/dev/null) || {
echo "error: no 'origin' remote configured" >&2
exit 1
}
PROJECT_NAME=$(basename "$ORIGIN_URL" .git)
# 1. Export database to JSONL
br sync --flush-only
# 2. Ensure local clone is up to date
if [ ! -d "$SYNC_REPO" ]; then
git clone "$REMOTE_REPO" "$SYNC_REPO"
else
git -C "$SYNC_REPO" pull --ff-only
fi
# 3. Ensure project subdirectory exists
PROJECT_DIR="$SYNC_REPO/$PROJECT_NAME"
mkdir -p "$PROJECT_DIR"
# 4. Copy tracked beads files into the project directory
COPIED=0
for f in \
.gitignore \
.jsonl.lock \
config.yaml \
interactions.jsonl \
issues.jsonl \
metadata.json \
README.md
do
if [ -f "$BEADS_DIR/$f" ]; then
cp "$BEADS_DIR/$f" "$PROJECT_DIR/$f"
COPIED=$((COPIED + 1))
fi
done
if [ "$COPIED" -eq 0 ]; then
echo "error: no trackable beads files found" >&2
exit 1
fi
# 5. Commit and push if there are changes
git -C "$SYNC_REPO" add -A
if git -C "$SYNC_REPO" diff --cached --quiet; then
echo "No beads changes to commit."
exit 0
fi
git -C "$SYNC_REPO" commit -m "sync beads: $PROJECT_NAME"
git -C "$SYNC_REPO" push
echo "Beads synced for $PROJECT_NAME to $(git -C "$SYNC_REPO" rev-parse --short HEAD)"