-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-commit.sh
More file actions
executable file
·32 lines (26 loc) · 885 Bytes
/
Copy pathdata-commit.sh
File metadata and controls
executable file
·32 lines (26 loc) · 885 Bytes
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
#!/bin/bash
#
# Auto-commit and push changes in the data/ repo.
# Add to /etc/cron.hourly/musicsite.sh alongside crontask.py.
#
# Usage:
# ./data-commit.sh # commit and push if changes exist
# ./data-commit.sh --test # dry run (show what would happen)
DATA_DIR="$(dirname "$(cd "$(dirname "$0")" && pwd)")/data"
if [ ! -d "$DATA_DIR/.git" ]; then
echo "data-commit: $DATA_DIR is not a git repo, skipping"
exit 0
fi
cd "$DATA_DIR"
# Check for any changes (staged, unstaged, or untracked)
if git diff --quiet HEAD 2>/dev/null && [ -z "$(git ls-files --others --exclude-standard)" ]; then
exit 0
fi
if [ "$1" = "--test" ]; then
echo "data-commit: would commit changes in $DATA_DIR:"
git status --short
exit 0
fi
git add -A
git commit -m "Auto-commit $(date '+%Y-%m-%d %H:%M')"
git push 2>/dev/null || echo "data-commit: push failed (will retry next run)"