diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-01-03 14:45:44 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-01-03 14:45:44 +0100 |
commit | 2bb34218520b9b95177e4f8421d2cdfe583a1420 (patch) | |
tree | 6667d055091bcfd818c3f26e02ffe2cbf2b34028 | |
parent | 5196c1ad9af6b0c045efecdb75f6228775e35cb0 (diff) | |
download | bin-2bb34218520b9b95177e4f8421d2cdfe583a1420.zip bin-2bb34218520b9b95177e4f8421d2cdfe583a1420.tar.gz |
git-sync: add functions success and fail, clean up a few
-rwxr-xr-x | git-synk | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -28,6 +28,14 @@ PURPLE="\033[0;35m" CYAN="\033[0;36m" YELLOW="\033[1;33m" +function success() { + echo -e "$1${GREEN}OK${RESET}" +} + +function fail() { + echo -e "${RED}$1 ${RESET}${CYAN}leave${RESET}\n" && cd .. +} + echo -e "remote:${YELLOW}${GIT_REMOTE}${RESET}:${PURPLE}${GIT_BRANCH}${RESET} USE_STASH=${RED}${USE_STASH}${RESET}" for gitdir in ${GIT_DIR}; do echo -e "enter ${BROWN}${gitdir}${RESET}" && cd ${gitdir} || return 1 @@ -36,41 +44,44 @@ for gitdir in ${GIT_DIR}; do [ -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 + echo -ne " ${CYAN}search remote${RESET}: ${YELLOW}${GIT_REMOTE}${RESET} ... " && \ + git remote show ${GIT_REMOTE} >/dev/null 2>&1 if [ $? -ne 0 ]; then - echo -e " ${RED}${GIT_REMOTE} remote not found ${RESET}" && cd .. && continue + fail "remote not found" && continue fi + success # CHECKOUT - echo -ne " ${CYAN}checkout $YELLOW$GIT_BRANCH$RESET ... " && git branch | grep -q -e " ${GIT_BRANCH}\$" && git checkout -q ${GIT_BRANCH} 2>/dev/null && echo -e "${GREEN}OK${RESET}" + echo -ne " ${CYAN}checkout branch $YELLOW$GIT_BRANCH$RESET ... " && \ + git branch | grep -q -e " ${GIT_BRANCH}\$" && git checkout -q ${GIT_BRANCH} 2>/dev/null && success if [ $? -ne 0 ]; then - echo -e "${RED}KO${RESET}" && cd .. && continue + fail "KO" && continue fi # GC + CLEAN - echo -ne " ${CYAN}clean$RESET ... " && git prune && git gc --quiet && git repack >/dev/null && git diff --quiet && echo -e "${GREEN}OK${RESET}" + echo -ne " ${CYAN}clean$RESET ... " && git prune && git gc --quiet && git repack >/dev/null && git diff --quiet && success if [ $? -ne 0 ]; then if [ "$action" = "push" ]; then - echo -e "dirty but ${GREEN}OK${RESET}" + success "dirty but " elif [ $USE_STASH -eq 1 ]; then STASH=1 echo -e "${RED}head is not clean, ${CYAN}git stash save${RESET}" && git stash save -q else - echo -e "${RED}head is not clean, USE_STASH=0 ... ${CYAN}leave${RESET}\n" && cd .. && continue + fail "head is not clean, USE_STASH=0 ... " && continue fi fi # PULL if [ "$action" != "push" ] ; then 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}" + git pull -q ${GIT_REMOTE} ${GIT_BRANCH} && success if [ $? -ne 0 ]; then - echo -e "${RED}KO${RESET}" && cd .. && continue + fail "KO" && continue fi fi # PUSH if [ "$action" != "pull" ] ; then echo -ne " ${CYAN}push${RESET}: ${YELLOW}${GIT_REMOTE}${RESET}:${PURPLE}${GIT_BRANCH}${RESET} ... " && \ - git push ${GIT_REMOTE} ${GIT_BRANCH} 2>/dev/null && echo -e "${GREEN}OK${RESET}" + git push ${GIT_REMOTE} ${GIT_BRANCH} 2>/dev/null && success if [ $? -ne 0 ]; then - echo -e "${RED}KO${RESET}" && cd .. && continue + fail "KO" && continue fi fi if [ $STASH -eq 1 ]; then |