Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
#set temp dir (from second arguments). defaults to __toupload
dest=${2:-__toupload}
dest=${dest%/}/
to="HEAD"
# get start revision from first argument (default to -1)
from=${1:-1}
re='^[0-9]+$'
# if argument is -x => take last x revisions
if [[ $from =~ $re ]]; then
from="HEAD~$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="$(git diff -r $to $from --name-status | 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 "====================="
git diff -r $to $from --name-status | 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
@yaronuliel
Copy link
Author

yaronuliel commented Jul 12, 2016

Installation:

  • download the file
  • give it execute permission (chmod +x git2ftp.sh)
  • Recommended: copy to you local bin directory (mv git2ftp.sh /usr/local/bin/git2ftp)

Usage Instructions:

To export the latest commit - run git2ftp
To export all changes since commit with hash HASH - run git2ftp HASH
To export changes in the last X commits - run git2ftp X (where X is the number of commits to export)

Note:
Deleted files are printed in the output of the execution - and you should manually delete them from the server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment