From 409b66964261460909e68a715b839d205d931610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 4 Jul 2011 09:10:07 +0200 Subject: git-synk: add colors, check if head is clean, add messages --- git-synk | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/git-synk b/git-synk index 491bc06..e17b076 100755 --- a/git-synk +++ b/git-synk @@ -1,31 +1,45 @@ #! /bin/sh GIT_BASE=${GIT_BASE:-$HOME/usr/git} -GIT_ORIGIN=${GIT_ORIGIN:-asynk} +GIT_REMOTE=${GIT_REMOTE:-asynk} +GIT_BRANCH=${GIT_BRANCH:-master} RESET="\033[0m" RED="\033[0;31m" +GREEN="\033[0;32m" BROWN="\033[0;33m" PURPLE="\033[0;35m" CYAN="\033[0;36m" +YELLOW="\033[1;33m" -function git_cmd () { - path=$1 - cmd=$2 - cd $path && echo -e "$BROWN$cmd$RESET within $RED$path$RESET" || return 1 +for gitdir in ${GIT_BASE}; do + echo -e "enter ${BROWN}${gitdir}${RESET}" && cd ${gitdir} || 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 + [ -d ${dir} ] && [ -e ${dir}/.git/config ] || continue + # SEARCH REMOTE + echo -e " enter ${BROWN}${dir}${RESET}" && cd $dir || exit 1 + git remote show ${GIT_REMOTE} >/dev/null 2>&1 if [ $? -ne 0 ]; then - echo -e " $RED$dir's head is not clear$RESET" && cd .. && continue + echo -e " ${RED}${GIT_REMOTE} remote not found ${RESET}" && cd .. && continue + fi + # GC + CLEAN + echo -ne " ${CYAN}clean$RESET ... " && git gc 2>/dev/null && git diff --quiet && echo -e "${GREEN}OK${RESET}" + if [ $? -ne 0 ]; then + echo -e "${RED}head is not clear${RESET}" && cd .. && continue + fi + # PULL + echo -ne " ${CYAN}pull${RESET}: ${YELLOW}${GIT_REMOTE}${RESET}:${PURPLE}${GIT_BRANCH}${RESET} ... " && \ + git pull -q ${GIT_REMOTE} ${GIT_BRANCH} && echo -e "${GREEN}OK${RESET}" + if [ $? -ne 0 ]; then + echo -e "${RED}KO${RESET}" && cd .. && continue + fi + # PUSH + echo -ne " ${CYAN}push${RESET}: ${YELLOW}${GIT_REMOTE}${RESET}:${PURPLE}${GIT_BRANCH}${RESET} ... " && \ + git push -q ${GIT_REMOTE} ${GIT_BRANCH} && echo -e "${GREEN}OK${RESET}" + if [ $? -ne 0 ]; then + echo -e "${RED}KO${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 + echo -e "leave ${BROWN}${gitdir}${RESET}" done -- cgit v1.1-2-g2b99