Skip to content

Instantly share code, notes, and snippets.

@bringhurst
Created April 30, 2010 19:30
Show Gist options
  • Save bringhurst/385651 to your computer and use it in GitHub Desktop.
Save bringhurst/385651 to your computer and use it in GitHub Desktop.
Subversion multiple project checkout script
#!/bin/bash
usage()
{
cat << EOF
usage: $0 [options] segments ...
This script will checkout the specified segment(s) from trunk.
OPTIONS:
-h Show this message
-t Specify the tag to checkout
-b Specify the branch to checkout
-a List available tags
-r List available branches
-v Be verbose with status and commands
EOF
}
SVN="svn"
SVND="http://<your svn repo here>"
REPO_TRUNK="trunk"
REPO_TAGS="tags"
REPO_BRANCHES="branches"
REPO_DIR=$REPO_TRUNK
TAG=
BRANCH=
LIST_TAG=
LIST_BRANCH=
VERBOSE=
while getopts ht:b:arv OPTION
do
case $OPTION in
h)
usage
exit 1
;;
t)
TAG=$OPTARG
REPO_DIR=$REPO_TAGS
shift $((OPTIND-1)); OPTIND=1
;;
b)
BRANCH=$OPTARG
REPO_DIR=$REPO_BRANCHES
shift $((OPTIND-1)); OPTIND=1
;;
a)
LIST_TAG=1
REPO_DIR=$REPO_TAGS
shift $((OPTIND-1)); OPTIND=1
;;
r)
LIST_BRANCH=1
REPO_DIR=$REPO_BRANCHES
shift $((OPTIND-1)); OPTIND=1
;;
v)
VERBOSE=1
shift $((OPTIND-1)); OPTIND=1
;;
?)
usage
exit 1
;;
esac
done
if [[ $TAG || $LIST_TAG ]]
then
if [[ $BRANCH || $LIST_BRANCH ]]
then
usage
exit 1
fi
if [[ $LIST_TAG && -z $TAG ]]
then
if [[ $VERBOSE ]]
then
echo "Listing tags for segments."
fi
for SEG in $*
do
if [[ $VERBOSE ]]
then
echo "$SVN ls $SVND/$SEG/$REPO_DIR"
fi
$SVN ls $SVND/$SEG/$REPO_DIR $SEG
done
exit 1
fi
if [[ -z $LIST_TAG && $TAG ]]
then
if [[ $VERBOSE ]]
then
echo "Checking out tag $TAG"
fi
for SEG in $*
do
if [[ $VERBOSE ]]
then
echo "$SVN co $SVND/$SEG/$REPO_DIR/$TAG $SEG"
fi
$SVN co $SVND/$SEG/$REPO_DIR/$TAG $SEG
done
exit 1
fi
usage
exit 1
fi
if [[ $BRANCH || $LIST_BRANCH ]]
then
if [[ $TAG || $LIST_TAG ]]
then
usage
exit 1
fi
if [[ $LIST_BRANCH && -z $BRANCH ]]
then
if [[ $VERBOSE ]]
then
echo "Listing branches for segments."
fi
for SEG in $*
do
if [[ $VERBOSE ]]
then
echo "$SVN ls $SVND/$SEG/$REPO_DIR"
fi
$SVN ls $SVND/$SEG/$REPO_DIR $SEG
done
exit 1
fi
if [[ -z $LIST_BRANCH && $BRANCH ]]
then
if [[ $VERBOSE ]]
then
echo "Checking out branch $BRANCH"
fi
for SEG in $*
do
if [[ $VERBOSE ]]
then
echo "$SVN co $SVND/$SEG/$REPO_DIR/$BRANCH $SEG"
fi
$SVN co $SVND/$SEG/$REPO_DIR/$BRANCH $SEG
done
exit 1
fi
usage
exit 1
fi
if [[ $VERBOSE ]]
then
echo "Checking out segments from trunk"
fi
for SEG in $*
do
if [[ $VERBOSE ]]
then
echo "$SVN co $SVND/$SEG/$REPO_DIR $SEG"
fi
$SVN co $SVND/$SEG/$REPO_DIR $SEG
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment