Skip to content

Instantly share code, notes, and snippets.

@skuro
Created December 19, 2012 13:29
Show Gist options
  • Select an option

  • Save skuro/4336656 to your computer and use it in GitHub Desktop.

Select an option

Save skuro/4336656 to your computer and use it in GitHub Desktop.
git-svn rebase all projects in one shot
#!/bin/sh
#
# Rebases all the incoming changes from remote subversion
# repositories. All repos are expected to be found as first
# children of a root folder. A log file is created per repo.
#
# author: Carlo Sciolla
# Root folder of all modules containing git-svn checkouts
BB_HOME=/Users/skuro/Development/Backbase/git
# Name of the logfile, hidden by default
LOG_NAME=.bbrebase.log
# we'll need it to return back to the original location
pushd . > /dev/null
# Use the echo program as the builting doesn't support -n
ECHO=$(which echo)
# Make sure any printed line has exactly 80 chars
# usage: padded "This is the main message" "[OK]"
function padded() {
MESSAGE=$1
RESULT=$2
SIZE=${#MESSAGE}
SIZE2=${#RESULT}
PADDING=$((80 - SIZE - SIZE2))
STR="$MESSAGE"
# pad the MESSAGE with trailing spaces
for i in $(seq $PADDING)
do
STR+=" "
done
$ECHO "$STR$RESULT"
}
for MODULE in $BB_HOME/*
do
NAME=$(basename $MODULE)
MESSAGE="Rebasing $NAME "
cd $MODULE
git svn rebase $MODULE > $MODULE/$LOG_NAME 2>&1
if [ $? -ne 0 ]
then
# prints 'FAIL' in red, then resets
FAIL="[$(tput setaf 1)FAIL$(tput sgr0)]"
padded "$MESSAGE" $FAIL
else
# prints 'OK' in green, then resets
OK="[$(tput setaf 2)OK$(tput sgr0)]"
padded "$MESSAGE" $OK
fi
done
# back to where we started
popd > /dev/null
skuro@Nur ~ $ bbrebase
Rebasing cxxxxxxxxxxxxxxxxxxxxxx [FAIL]
Rebasing cxxxxxxxxxxxxxx [FAIL]
Rebasing cxx [OK]
Rebasing cxxxxxx [OK]
Rebasing cxxxxxx [OK]
Rebasing exxxxxxx [FAIL]
Rebasing fxxxxxxxxx [OK]
Rebasing lxxxxxxx [FAIL]
Rebasing mxxxxxx [OK]
skuro@Nur ~ $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment