From bf1390a24e27b23b3eabae2108ad8f1ea2bd8805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 10 Jul 2011 07:53:48 +0200 Subject: git-svn-helper: get ready for batch mode, add some error messages, fix error function, ... --- git-svn-helper | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/git-svn-helper b/git-svn-helper index 505691d..936feb7 100755 --- a/git-svn-helper +++ b/git-svn-helper @@ -6,7 +6,11 @@ RED="\033[0;31m" RESET="\033[0m" function error () { - echo -e " => ${RED}FAILURE${RESET}" && exit 1 + echo -e " $1 => ${RED}FAILURE${RESET}" && exit 1 +} + +function say () { + [ $BATCH_MODE == 0 ] && echo -e "$1" } [ -e $GIT_SVN_CONFIG ] || error "$GIT_SVN_CONFIG does not exists!" @@ -19,8 +23,9 @@ source ./$GIT_SVN_CONFIG LOCAL_REPO=${LOCAL_REPO:-"local"} LOCAL_DIR=${LOCAL_DIR:-"${GIT_BASE}/${PRJ}"} +SVN_SUFFIX=_svn SVN_CLONE_REPO=${SVN_CLONE_REPO:-"svn_clone"} -SVN_CLONE_DIR=${SVN_CLONE_DIR:-"${GIT_BASE}/${PRJ}_svn"} +SVN_CLONE_DIR=${SVN_CLONE_DIR:-"${GIT_BASE}/${PRJ}${SVN_SUFFIX}"} URL_COLOR="\033[0;34m" LRC="\033[0;33m" # LOCAL REPO COLOR @@ -104,23 +109,24 @@ if [ ! -d ${LOCAL_DIR} ]; then ask_ok "create local repository within ${LRC}${LOCAL_DIR}${RESET} " && create_local_repo fi -cd ${LOCAL_DIR} -LOCAL_B=$(git branch |grep '*' | gawk '{print $2;}') || error -LOCAL_HEAD=$(git show --format="%H" HEAD | head -n 1 | gawk '{print $1 }') || error -echo -e "** ${LRC}${LOCAL_REPO}${RESET} current branch is ${LBC}${LOCAL_B}${RESET} head ${RED}${LOCAL_HEAD}${RESET}" -cd ${SVN_CLONE_DIR} +cd ${LOCAL_DIR} || error "${LOCAL_DIR} does not exists" +LOCAL_B=$(git branch |grep '*' | gawk '{print $2;}') || error "unable to list local branches" +LOCAL_HEAD=$(git log --pretty="format:%H" HEAD~1..) || error "unable to read local head" +say "** ${LRC}${LOCAL_REPO}${RESET} current branch is ${LBC}${LOCAL_B}${RESET} head ${RED}${LOCAL_HEAD}${RESET}" +cd ${SVN_CLONE_DIR} || error "${SVN_CLONE_DIR} does not exists" SVN_CLONE_B=${LOCAL_B}_svn -SVN_HEAD=$(git show --format="%H" HEAD | head -n 1 | gawk '{print $1 }') || error -echo -e "** ${LRC}${SVN_CLONE_REPO}${RESET} corresponding branch is ${LBC}${SVN_CLONE_B}${RESET} head ${RED}${SVN_HEAD}${RESET}" +git checkout ${SVN_CLONE_B} +SVN_HEAD=$(git log --pretty="format:%H" HEAD~1..) || error "unable to read local head" +say "** ${LRC}${SVN_CLONE_REPO}${RESET} corresponding branch is ${LBC}${SVN_CLONE_B}${RESET} head ${RED}${SVN_HEAD}${RESET}" cd ${LOCAL_DIR} while [ 1 ]; do - echo -e "\nOptions :" - echo -e " # 1) ${RED}fetch svn${RESET} and update branches within ${SRC}${SVN_CLONE_DIR}${RESET}" - echo -e " # 2) ${RED}push${RESET} ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" - echo -e " # 3) ${RED}push${RESET} ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} to ${URL_COLOR}${SVN_URL}${RESET}" - echo -e " # 4) ${RED}pull${RESET} ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} within ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET}" - echo -e " # q) ${RED}QUIT${RESET}" + say "\nOptions :" + say " # 1) ${RED}fetch svn${RESET} and update branches within ${SRC}${SVN_CLONE_DIR}${RESET}" + say " # 2) ${RED}push${RESET} ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" + say " # 3) ${RED}push${RESET} ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} to ${URL_COLOR}${SVN_URL}${RESET}" + say " # 4) ${RED}pull${RESET} ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} within ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET}" + say " # q) ${RED}QUIT${RESET}" echo -n -e "\nyour choice : " read CHOICE echo "" -- cgit v1.1-2-g2b99 From 2f5f612056a2c0276aa071bb55704bca4cae3ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 10 Jul 2011 07:55:01 +0200 Subject: git-svn-helper: use say function and a few changes --- git-svn-helper | 84 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/git-svn-helper b/git-svn-helper index 936feb7..59a3317 100755 --- a/git-svn-helper +++ b/git-svn-helper @@ -34,72 +34,78 @@ SRC="\033[0;35m" # SVN CLONE REPO COLOR SBC="\033[0;32m" # SVN CLONE BRANCH COLOR DSBC="\033[0;37m" # DISTANT SVN BRANCH COLOR +BATCH_MODE=0 + function ask_ok () { - echo -n -e "$1${RESET}[${RED}Y${RESET}n] : " + [ $BATCH_MODE == 1 ] && return 0 + echo -e -n "$1${RESET}[${RED}Y${RESET}n] : " read OK if [ "$OK" = "" -o "$OK" = "y" -o "$OK" = "Y" ]; then return 0 fi - echo -e "${RED}abort${RESET}" && return 1 + say "${RED}abort${RESET}" && return 1 } function create_svn_clone () { - echo -e "** clone from ${URL_COLOR}${SVN_URL}${RESET}" && cd $GIT_BASE && git svn clone ${SVN_URL} -T trunk -b branches -t tags ${PRJ}_svn || error + say "** clone from ${URL_COLOR}${SVN_URL}${RESET}" && cd $GIT_BASE && git svn clone ${SVN_URL} -T trunk -b branches -t tags ${SVN_CLONE_DIR} || error cd ${SVN_CLONE_DIR} for branch in $BRANCHES_TO_TRACK; do - echo -e "** checkout ${DSBC}${branch}${RESET} in ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${branch}_svn${RESET}" && git checkout $branch -b ${branch}_svn || error + say "** checkout ${DSBC}${branch}${RESET} in ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${branch}${SVN_SUFFIX}${RESET}" && \ + git checkout $branch -b ${branch}${SVN_SUFFIX} || error done - echo -e "** add ${LRC}${LOCAL_DIR}${RESET} as repo ${LRC}${LOCAL_REPO}${RESET}" && git remote add ${LOCAL_REPO} ${LOCAL_DIR} || error + say "** remove master branch" && git branch -D master || error + say "** add ${LRC}${LOCAL_DIR}${RESET} as repo ${LRC}${LOCAL_REPO}${RESET}" && git remote add ${LOCAL_REPO} ${LOCAL_DIR} || error } function create_local_repo () { - echo -e "** git init ${LRC}${LOCAL_DIR}${RESET}" && git init ${LOCAL_DIR}|| error - echo -e "** cd ${LRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error - echo -e "** add ${SRC}${SVN_CLONE_DIR}${RESET} as repo ${SRC}${SVN_CLONE_REPO}${RESET}" && git remote add ${SVN_CLONE_REPO} ${SVN_CLONE_DIR} || error - echo -e "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error + say "** git init ${LRC}${LOCAL_DIR}${RESET}" && git init ${LOCAL_DIR}|| error + say "** cd ${LRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error + say "** add ${SRC}${SVN_CLONE_DIR}${RESET} as repo ${SRC}${SVN_CLONE_REPO}${RESET}" && git remote add ${SVN_CLONE_REPO} ${SVN_CLONE_DIR} || error + say "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error for branch in $BRANCHES_TO_TRACK; do - echo -e "** checkout ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${branch}_svn${RESET} to ${SBC}${branch}${RESET}" && git checkout ${SVN_CLONE_REPO}/${branch}_svn -b ${branch} || error + say "** checkout ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${branch}${SVN_SUFFIX}${RESET} to ${SBC}${branch}${RESET}" && \ + git checkout ${SVN_CLONE_REPO}/${branch}${SVN_SUFFIX} -b ${branch} || error done } function fetch_svn () { - echo -e "** cd ${SRC}${SVN_CLONE_DIR}${RESET}" && cd ${SVN_CLONE_DIR} || error - echo -e "** fetch from ${URL_COLOR}${SVN_URL}${RESET}" && git svn fetch || error - BRANCHES=$(git branch | sed -e s/*//) + say "** cd ${SRC}${SVN_CLONE_DIR}${RESET}" && cd ${SVN_CLONE_DIR} || error + say "** fetch from ${URL_COLOR}${SVN_URL}${RESET}" && git svn fetch || error + BRANCHES=$(git for-each-ref --format="%(refname:short)" refs/heads/) for branch in $BRANCHES; do - echo -e "** rebase ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${branch}${RESET}" && git checkout $branch && git svn rebase || error + say "** rebase ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${branch}${RESET}" && git checkout $branch && git svn rebase || error done - echo -e "** cd ${SRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error - echo -e "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error -} - -function pull_from_clone () { - #echo -e "** cd ${SRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error - #echo -e "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error - #echo -e "** merge ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} within ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET}" && git merge ${SVN_CLONE_REPO}/${SVN_CLONE_B} || error - echo -e "To do so :" - echo -e " ${LRC}- save your current work ${SRC}$ git stash save NAME${RESET}" - echo -e " ${LRC}- leave your current branch ${SRC}$ git checkout ANOTHER_BRANCH${RESET}" - echo -e " ${LRC}- delete your branch ${SRC}$ git branch -D ${LOCAL_B}${RESET}" - echo -e " ${LRC}- checkout your branch ${SRC}$ git checkout ${SVN_CLONE_REPO}/${LOCAL_B}_svn -b ${LOCAL_B}${RESET}" - echo -e " ${LRC}- apply your current work ${SRC}$ git stash pop/apply${RESET}" + say "** cd ${SRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error + say "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error } function push_to_clone () { - echo -e "** cd ${SRC}${SVN_CLONE_DIR}${RESET}" && cd ${SVN_CLONE_DIR} || error - echo -e "** checkout ${SBC}${SVN_CLONE_B}${RESET}" && git checkout ${SVN_CLONE_B} || error - echo -e "** fetch ${LRC}${LOCAL_REPO}${RESET}" && git fetch ${LOCAL_REPO} || error - echo -e "** rebase ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" && git rebase ${LOCAL_REPO}/${LOCAL_B} || error - #git log --format="%H %an %s" $SVN_HEAD..$LOCAL_HEAD - echo -e "** cd ${SRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error - echo -e "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error + say "** cd ${SRC}${SVN_CLONE_DIR}${RESET}" && cd ${SVN_CLONE_DIR} || error + say "** fetch ${LRC}${LOCAL_REPO}${RESET}" && git fetch ${LOCAL_REPO} || error + say "** checkout ${SBC}${SVN_CLONE_B}${RESET}" && git checkout ${SVN_CLONE_B} || error + say "** rebase ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" && \ + git rebase ${LOCAL_REPO}/${LOCAL_B} || error + say "** cd ${SRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error + say "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error } function dcommit () { - echo -e "** cd ${SRC}${SVN_CLONE_DIR}${RESET}" && cd ${SVN_CLONE_DIR} || error - echo -e "** checkout ${SBC}${SVN_CLONE_B}${RESET}" && git checkout ${SVN_CLONE_B} || error - echo -e "** rebase ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" && git svn rebase || error - echo -e "** dcommit ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} to ${URL_COLOR}${SVN_URL}${RESET}" && git svn dcommit + say "** cd ${SRC}${SVN_CLONE_DIR}${RESET}" && cd ${SVN_CLONE_DIR} || error + say "** checkout ${SBC}${SVN_CLONE_B}${RESET}" && git checkout ${SVN_CLONE_B} || error + say "** rebase ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" && git svn rebase || error + say "** dcommit ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} to ${URL_COLOR}${SVN_URL}${RESET}" && git svn dcommit +} + +function pull_from_clone () { + #say "** cd ${SRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error + #say "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error + #say "** merge ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} within ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET}" && git merge ${SVN_CLONE_REPO}/${SVN_CLONE_B} || error + say "To do so :" + say " ${LRC}- save your current work ${SRC}$ git stash save NAME${RESET}" + say " ${LRC}- leave your current branch ${SRC}$ git checkout ANOTHER_BRANCH${RESET}" + say " ${LRC}- delete your branch ${SRC}$ git branch -D ${LOCAL_B}${RESET}" + say " ${LRC}- checkout your branch ${SRC}$ git checkout ${SVN_CLONE_REPO}/${LOCAL_B}${SVN_SUFFIX} -b ${LOCAL_B}${RESET}" + say " ${LRC}- apply your current work ${SRC}$ git stash pop/apply${RESET}" } if [ ! -d ${SVN_CLONE_DIR} ]; then -- cgit v1.1-2-g2b99 From 82d2640802b88e05e6575994c08c4aae0cb61abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 10 Jul 2011 11:08:19 +0200 Subject: easy_e17.sh: rename SVN_CLONE_B into SVN_B --- git-svn-helper | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/git-svn-helper b/git-svn-helper index 59a3317..ce2eca1 100755 --- a/git-svn-helper +++ b/git-svn-helper @@ -82,8 +82,8 @@ function fetch_svn () { function push_to_clone () { say "** cd ${SRC}${SVN_CLONE_DIR}${RESET}" && cd ${SVN_CLONE_DIR} || error say "** fetch ${LRC}${LOCAL_REPO}${RESET}" && git fetch ${LOCAL_REPO} || error - say "** checkout ${SBC}${SVN_CLONE_B}${RESET}" && git checkout ${SVN_CLONE_B} || error - say "** rebase ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" && \ + say "** checkout ${SBC}${SVN_B}${RESET}" && git checkout ${SVN_B} || error + say "** rebase ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_B}${RESET}" && \ git rebase ${LOCAL_REPO}/${LOCAL_B} || error say "** cd ${SRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error say "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error @@ -91,15 +91,15 @@ function push_to_clone () { function dcommit () { say "** cd ${SRC}${SVN_CLONE_DIR}${RESET}" && cd ${SVN_CLONE_DIR} || error - say "** checkout ${SBC}${SVN_CLONE_B}${RESET}" && git checkout ${SVN_CLONE_B} || error - say "** rebase ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" && git svn rebase || error - say "** dcommit ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} to ${URL_COLOR}${SVN_URL}${RESET}" && git svn dcommit + say "** checkout ${SBC}${SVN_B}${RESET}" && git checkout ${SVN_B} || error + say "** rebase ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_B}${RESET}" && git svn rebase || error + say "** dcommit ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_B}${RESET} to ${URL_COLOR}${SVN_URL}${RESET}" && git svn dcommit } function pull_from_clone () { #say "** cd ${SRC}${LOCAL_DIR}${RESET}" && cd ${LOCAL_DIR} || error #say "** fetch ${SRC}${SVN_CLONE_REPO}${RESET}" && git fetch ${SVN_CLONE_REPO} || error - #say "** merge ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} within ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET}" && git merge ${SVN_CLONE_REPO}/${SVN_CLONE_B} || error + #say "** merge ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_B}${RESET} within ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET}" && git merge ${SVN_CLONE_REPO}/${SVN_B} || error say "To do so :" say " ${LRC}- save your current work ${SRC}$ git stash save NAME${RESET}" say " ${LRC}- leave your current branch ${SRC}$ git checkout ANOTHER_BRANCH${RESET}" @@ -120,18 +120,18 @@ LOCAL_B=$(git branch |grep '*' | gawk '{print $2;}') || error "unable to list lo LOCAL_HEAD=$(git log --pretty="format:%H" HEAD~1..) || error "unable to read local head" say "** ${LRC}${LOCAL_REPO}${RESET} current branch is ${LBC}${LOCAL_B}${RESET} head ${RED}${LOCAL_HEAD}${RESET}" cd ${SVN_CLONE_DIR} || error "${SVN_CLONE_DIR} does not exists" -SVN_CLONE_B=${LOCAL_B}_svn -git checkout ${SVN_CLONE_B} +SVN_B=${LOCAL_B}_svn +git checkout ${SVN_B} SVN_HEAD=$(git log --pretty="format:%H" HEAD~1..) || error "unable to read local head" -say "** ${LRC}${SVN_CLONE_REPO}${RESET} corresponding branch is ${LBC}${SVN_CLONE_B}${RESET} head ${RED}${SVN_HEAD}${RESET}" +say "** ${LRC}${SVN_CLONE_REPO}${RESET} corresponding branch is ${LBC}${SVN_B}${RESET} head ${RED}${SVN_HEAD}${RESET}" cd ${LOCAL_DIR} while [ 1 ]; do say "\nOptions :" say " # 1) ${RED}fetch svn${RESET} and update branches within ${SRC}${SVN_CLONE_DIR}${RESET}" - say " # 2) ${RED}push${RESET} ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET}" - say " # 3) ${RED}push${RESET} ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} to ${URL_COLOR}${SVN_URL}${RESET}" - say " # 4) ${RED}pull${RESET} ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_CLONE_B}${RESET} within ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET}" + say " # 2) ${RED}push${RESET} ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_B}${RESET}" + say " # 3) ${RED}push${RESET} ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_B}${RESET} to ${URL_COLOR}${SVN_URL}${RESET}" + say " # 4) ${RED}pull${RESET} ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_B}${RESET} within ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET}" say " # q) ${RED}QUIT${RESET}" echo -n -e "\nyour choice : " read CHOICE -- cgit v1.1-2-g2b99 From 33cea2a1efdc31af12bfe4efffc3d79ce00f1b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 10 Jul 2011 11:57:03 +0200 Subject: easy_e17.sh: batch mode is usable --- git-svn-helper | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/git-svn-helper b/git-svn-helper index ce2eca1..6e94f6f 100755 --- a/git-svn-helper +++ b/git-svn-helper @@ -1,6 +1,19 @@ #! /bin/bash -GIT_SVN_CONFIG=${1:-".git_svn_config"} +ACTIONS='' +for arg in $@; do + case "$arg" in + pull|push|commit) + ACTIONS="$ACTIONS $arg" + ;; + *) + GIT_SVN_CONFIG=$arg + ;; + esac +done +BATCH_MODE=0 +[ ! -z "$ACTIONS" ] && BATCH_MODE=1 +GIT_SVN_CONFIG=${GIT_SVN_CONFIG:-".git_svn_config"} RED="\033[0;31m" RESET="\033[0m" @@ -11,6 +24,7 @@ function error () { function say () { [ $BATCH_MODE == 0 ] && echo -e "$1" + return 0 } [ -e $GIT_SVN_CONFIG ] || error "$GIT_SVN_CONFIG does not exists!" @@ -34,8 +48,6 @@ SRC="\033[0;35m" # SVN CLONE REPO COLOR SBC="\033[0;32m" # SVN CLONE BRANCH COLOR DSBC="\033[0;37m" # DISTANT SVN BRANCH COLOR -BATCH_MODE=0 - function ask_ok () { [ $BATCH_MODE == 1 ] && return 0 echo -e -n "$1${RESET}[${RED}Y${RESET}n] : " @@ -126,7 +138,7 @@ SVN_HEAD=$(git log --pretty="format:%H" HEAD~1..) || error "unable to read local say "** ${LRC}${SVN_CLONE_REPO}${RESET} corresponding branch is ${LBC}${SVN_B}${RESET} head ${RED}${SVN_HEAD}${RESET}" cd ${LOCAL_DIR} -while [ 1 ]; do +while [ -z "$ACTIONS" ]; do say "\nOptions :" say " # 1) ${RED}fetch svn${RESET} and update branches within ${SRC}${SVN_CLONE_DIR}${RESET}" say " # 2) ${RED}push${RESET} ${LRC}${LOCAL_REPO}${RESET}/${LBC}${LOCAL_B}${RESET} within ${SRC}${SVN_CLONE_REPO}${RESET}/${SBC}${SVN_B}${RESET}" @@ -154,3 +166,15 @@ while [ 1 ]; do ;; esac done + +if [ ! -z "$ACTIONS" ]; then + for action in $ACTIONS; do + if [ "$action" == "pull" ]; then + fetch_svn + elif [ "$action" == "push" ]; then + push_to_clone + elif [ "$action" == "commit" ]; then + dcommit + fi + done +fi -- cgit v1.1-2-g2b99