~kris/dots

srice

srice/.local/bin/dev/push -rw-r--r-- 1.8 KiB
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
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
#!/bin/bash
# push: push all git repos in ~/dev that have your own remotes
# usage: push          -- direct push of committed changes
#        push --smart  -- use claude to commit+push intelligently

LOGFILE="$HOME/.local/share/dev-push.log"
DEVDIR="$HOME/dev"

smart=0
[ "$1" = "--smart" ] && smart=1

if [ "$smart" -eq 1 ]; then
    echo "$(date '+%Y-%m-%d %H:%M:%S') — push --smart: attempting claude" >> "$LOGFILE"
    timeout 120 claude --dangerously-skip-permissions -p \
        "Run push for me. For each git repo in ~/dev that is owned by krisyotam on GitHub, check if there are unpushed commits or uncommitted changes. If there are uncommitted changes, create a sensible commit and push. If already up to date, skip it. Be efficient — only report repos where you took action." \
        --allowedTools "Bash(command:*)" \
        2>> "$LOGFILE"
    if [ $? -eq 0 ]; then
        exit 0
    fi
    echo "$(date '+%Y-%m-%d %H:%M:%S') — claude unavailable, falling back to direct push" >> "$LOGFILE"
fi

echo "$(date '+%Y-%m-%d %H:%M:%S') — push starting" >> "$LOGFILE"

for d in "$DEVDIR"/*/; do
    [ -d "$d/.git" ] || continue
    name="$(basename "$d")"

    remote_url="$(git -C "$d" remote get-url origin 2>/dev/null)"
    [ -z "$remote_url" ] && continue
    echo "$remote_url" | grep -qiE 'krisyotam|krisportfolio' || continue

    local_ref="$(git -C "$d" rev-parse HEAD 2>/dev/null)"
    tracking="$(git -C "$d" rev-parse '@{u}' 2>/dev/null)"
    [ "$local_ref" = "$tracking" ] 2>/dev/null && continue

    echo "$(date '+%Y-%m-%d %H:%M:%S') — pushing $name" >> "$LOGFILE"
    git -C "$d" push 2>> "$LOGFILE" && \
        echo "$(date '+%Y-%m-%d %H:%M:%S')$name pushed OK" >> "$LOGFILE" || \
        echo "$(date '+%Y-%m-%d %H:%M:%S')$name FAILED" >> "$LOGFILE"
done

echo "$(date '+%Y-%m-%d %H:%M:%S') — push complete" >> "$LOGFILE"