Skip to content

Instantly share code, notes, and snippets.

@yaronuliel
Last active Jun 28, 2016
Embed
What would you like to do?
This is a script for extracting the files that was changed in the most recent svn commit into a separate directory for upload to server (using FTP/SSH/whatever)
#!/usr/bin/env bash
#set temp dir (from second arguments). defaults to __toupload
dest=${2:-__toupload}
dest=${dest%/}/
to=$(svn info --show-item revision)
# get start revision from first argument (default to -1)
from=${1:--1}
# if argument is -x => take last x revisions
if [ $from -lt 0 ]; then
from=`expr $to + $from`
fi
# don't allow the use of an existing directory as temp directory
if [ -d $dest ]; then
printf "\033[1;31m[ERROR] Temp directory must not exist.\033[0m Delete ${dest} to proceed.\n\n"
rm -R $dest
exit
fi
# get list of the added/modified file in the last commit
files="$(svn diff -r $from:$to . --summarize | grep ^[AM]\\s | awk '{print $2}')"
#for each of those files
while IFS= read line
do
dir="$(dirname $line)"
#if its dir doesn't exist in the temp dir - create it
if [ ! -d "${dest}${dir}" ]; then
mkdir -p ${dest}${dir}
echo "Creating dir ${dest}${dir}"
fi
# copy the file to the temp dir
cp $line ${dest}${line}
done <<< "$files"
printf "\033[1;32mFiles to upload ready in ${dest}\033[0m\n"
#print list of files that need to be deleted manually on server
echo "Files to delete: "
echo "====================="
svn diff -r $from:$to . --summarize | grep ^D | awk '{printf "*\t\033[1;31m"$2"\033[0m\n"}'
# Wait for user to confirm that he has performed the upload - only then delete the temp dir
printf "\033[1;32mUpload the files and click any key in order to delete the temp dir\033[0m\n"
read something
rm -R $dest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment