summaryrefslogtreecommitdiffstats
path: root/git-synk
blob: 491bc06f4ca81f33905e59fc64ef8a7f193b7976 (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
#! /bin/sh

GIT_BASE=${GIT_BASE:-$HOME/usr/git}
GIT_ORIGIN=${GIT_ORIGIN:-asynk}

RESET="\033[0m"
RED="\033[0;31m"
BROWN="\033[0;33m"
PURPLE="\033[0;35m"
CYAN="\033[0;36m"

function git_cmd () {
    path=$1
    cmd=$2
    cd $path && echo -e "$BROWN$cmd$RESET within $RED$path$RESET" || return 1
    for dir in $(ls -1); do
        [ -d $dir ] && [ -e $dir/.git/config ] || continue
        cd $dir
        git gc 2>/dev/null && git diff --quiet
        if [ $? -ne 0 ]; then
            echo -e "   $RED$dir's head is not clear$RESET" && cd .. && continue
        fi
        git remote show $GIT_ORIGIN >/dev/null 2>&1 && echo -e "   $CYAN$cmd:$BROWN $dir$RESET" && git $cmd $GIT_ORIGIN master
        cd ..
    done
}

for gitdir in $GIT_BASE; do
    git_cmd "$gitdir" pull
    git_cmd "$gitdir" push
done