aboutsummaryrefslogblamecommitdiffstats
path: root/git-package
blob: 4becad9d1deb3833d0464ef87df07399c258fb9e (plain) (tree)
































                                                                               
#!/bin/sh

set -e

git rev-parse || exit 1

errx() {
	printf '%s\n' "$*" >&2
	exit 1
}

usage() {
	errx 'usage: git package [-f format] tree-ish [path...]'
}

format="$(git config --get package.format)"
: "${format:=tar.gz}"

while getopts f: opt; do
	case $opt in
		f) format=$OPTARG;;
		?) usage;;
	esac
done
shift $((OPTIND - 1))
test $# -ge 1 || usage

git archive -l | grep -Fqx "$format" || err "fatal: unknown format"

name="$(basename "$(git rev-parse --show-toplevel)")"
treeish="$1"

exec git archive --prefix="$name-$treeish/" -o "$name-$treeish.$format" -- "$@"