Created
April 16, 2014 06:10
-
-
Save iNamik/10814849 to your computer and use it in GitHub Desktop.
Bash Script to Cleanup an SVN checkout, Revert local changes and Update to @Head - Does not generate any output unless something is changed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# svnCleanUpdate | |
# | |
# Cleanup an SVN checkout, Revert local changes and update to @HEAD | |
# Does not generate any output unless something is changed. | |
# NOTE: This script destroys all local mods - run it with caution! | |
#SVN_AUTH="--username user --password passwd" | |
SVN_AUTH="" | |
if [ "$1" == "" ] ; then | |
echo "usage: $0 svn_root_dir" >&2 | |
echo "NOTE: This script destroys all local mods - run it with caution!" >&2 | |
exit 1; | |
fi | |
if [ ! -d "$1" ] ; then | |
echo "$2 is not a directory" | |
exit 1; | |
fi | |
#SVNDIR=$( readlink -e "$1" ) | |
SVNDIR="$1" | |
cd "$SVNDIR" | |
if [ ! -d './.svn' ] ; then | |
echo "$2 is not under version control" | |
exit 1; | |
fi | |
# SVN Cleanup | |
SVN_CLEANUP="svn cleanup ${SVN_AUTH} ." | |
CLEANUP=$( $SVN_CLEANUP ) | |
if [ ! "${CLEANUP}" == "" ] ; then | |
echo | |
echo "CLEANING UP WORKING COPY:" | |
echo | |
echo "${CLEANUP}" | |
fi | |
# Revert any local modifications | |
SVN_REVERT="svn revert ${SVN_AUTH} --depth infinity ." | |
REVERTED=$( $SVN_REVERT ) | |
if [ ! "${REVERTED}" == "" ] ; then | |
echo | |
echo "REVERTING LOCAL MODIFICATIONS:" | |
echo | |
echo "${REVERTED}" | |
fi | |
# Delete any local additions | |
SVN_STATUS="svn status ${SVN_AUTH}" | |
DELETED="" | |
for file in $( $SVN_STATUS | grep '^?' | cut -c9- ) ; do | |
if [ "${DELETED}" == "" ] ; then | |
echo | |
echo | |
echo "DELETING LOCAL ADDITIONS:" | |
echo | |
DELETED=1 | |
fi | |
if [ -f $file ] ; then | |
echo "F '${file}'" | |
rm -f ${file} | |
elif [ -d $file ] ; then | |
echo "D '${file}'" | |
rm -rf ${file} | |
else | |
echo "? '${file}'" | |
fi | |
done | |
# Update Repository | |
SVN_UPDATE="svn update ${SVN_AUTH} --force ." | |
UPDATED_FULL=$( $SVN_UPDATE ) | |
UPDATED=$( echo "${UPDATED_FULL}" | grep -v 'At revision' ) | |
if [ ! "${UPDATED}" == "" ] ; then | |
echo | |
echo "UPDATING FROM REPOSITORY:" | |
echo | |
echo "${UPDATED_FULL}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment