Created
July 12, 2016 18:45
-
-
Save yaronuliel/6fcceba20888116c91eee314655df69f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation:
chmod +x git2ftp.sh
)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