Some code i wrote to do git export like svn export.
#!/bin/bash
######################################################################
# Simple script that will export a git version similar to svn export #
# Created 07/18/2012 by Edward Mann edmann.com #
######################################################################
GIT=`which git`
TAR=`which tar`
######################################################################
# Don't change the below, unless you know what you are doing. #
######################################################################
REMOTE=$1
TREE=$2
DIR=$3
RED='\e[1;31m'
BLUE='\e[1;34m'
#
# Check that our git executable is present and
# also that we have a good tar executable
#
checkSetup() {
echo -e "${BLUE}Checking setup..."
if [ ! -x ${GIT} ];
then
echo -e "${RED}The path i have set for the git executables is either wrong or not executable!"
exit 1
fi
if [ ! -x ${TAR} ]
then
echo -e "${RED}The path i have set for the tar executables is either wrong or not executable!"
exit 1
fi
if [ "${REMOTE}" == "" ] || [ "${TREE}" == "" ] || [ "${DIR}" == "" ];
then
showUsage
exit 1
fi
}
showUsage(){
echo "Usage:"
echo "git-export <repo> <tree> <dir>"
echo "<repo>: Source to create export from."
echo "<tree>: The tree or commit to produce an export for."
echo "<dir>: The directory to store the export into."
}
#
# Check that our directory does not exist. I don't want to remove the directory or overwrite the
# directory. This will hopefully prevent someone from destroying a directory acidentally.
#
checkDir(){
if [ -d ${DIR} ]
then
echo -e "${RED}The directory '${DIR}' exists, please remove the directory first."
exit 1
else
echo -e "${BLUE}Creating directory '${DIR}'..."
mkdir ${DIR}
fi
}
doExport(){
echo -e "${BLUE}Running Export..."
`${GIT} archive --format=tar --remote=${REMOTE} ${TREE} | (cd ${DIR} && ${TAR} -xf -)`
}
checkSetup
checkDir
doExport