Skip to content

Instantly share code, notes, and snippets.

@neckro
Last active December 23, 2015 12:59
Show Gist options
  • Save neckro/6638797 to your computer and use it in GitHub Desktop.
Save neckro/6638797 to your computer and use it in GitHub Desktop.
Lazy dev script. Quickly copy your files since whatever Git revision to remote server.
#!/usr/bin/env sh
IFS=$'\n'
export dest=$1
revision=$2
default_revision="HEAD~1"
function tar_upload() {
local server=${dest%:*}
local remote_dir=${dest#*:}
sed -e 's/^.*-\> //g' |\
add_quotes |\
xargs tar cz |\
ssh "$server" tar xzv --warning=timestamp -C "$remote_dir"
}
function add_quotes() {
while read line; do
if [ -e "$line" ]; then
echo \"$line\"
else
echo "File no longer exists: $line" 1>&2
fi
done
}
if [ -z "$dest" ]; then
echo "usage: $( basename "$0" ) <destination> <revision>"
exit
fi
# go to root of repo
cd "$( git rev-parse --show-toplevel )"
# check revision
[ -z "$revision" ] && revision="$default_revision"
# show the revision we're uploading
git show --oneline "$revision" | head -n1
# see if there's anything to do
git diff --quiet "$revision"
if [ $? -eq 0 ]; then
echo "No changes; nothing to upload!"
else
git diff --name-only "$revision" | tar_upload
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment