Skip to content

Instantly share code, notes, and snippets.

@Mossuru777
Last active August 29, 2015 14:16
Show Gist options
  • Save Mossuru777/6f8481c07aedb555d3ef to your computer and use it in GitHub Desktop.
Save Mossuru777/6f8481c07aedb555d3ef to your computer and use it in GitHub Desktop.
#!/bin/bash
red=31
green=32
lightblue=36
function cecho {
color=$1
shift
echo -e "\033[${color}m$@\033[m"
}
function usage {
echo -en "
$(basename ${0}) is a tool that create
\033[${lightblue}mPatch\033[m and \033[${lightblue}mZip-archive(include only added,modified,created,renamed files)\033[m
for delivery.
Usage:
$(basename ${0}) [-h] Commit-A-Hash Commit-B-Hash OutputFilePathPrefix (ExcludePath(s)Regex)
Options:
-h print this
"
exit 1
}
# Parameter Check
while getopts h OPT
do
case ${OPT} in
h|*)
usage
;;
esac
done
if [ "${OPTIND}" -gt "0" ]; then
shift `expr ${OPTIND} - 1`
fi
if [ "$#" -lt "3" -o "$#" -gt "4" ]; then
usage
fi
# Create Patch
git diff ${1}..${2} --name-only | grep -E -v ${4} | xargs git diff --no-prefix ${1}..${2} -- > ${3}.patch
if [ "$?" -ne "0" ]; then
cecho $red "can't create patch."
exit 1
fi
cecho $green "create patch to ${3}.patch"
# Create Zip-archive
git archive -9 --format=zip ${2} `git diff --diff-filter=AMCR --name-only ${1}..${2} | grep -E -v ${4} | xargs git diff --diff-filter=AMCR --name-only ${1}..${2} -- ` -o ${3}.zip
if [ "$?" -ne "0" ]; then
cecho $red "can't create Zip-archive."
exit 1
fi
cecho $green "create Zip-archive to ${3}.zip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment