aboutsummaryrefslogtreecommitdiffstats
path: root/git-package
blob: 2bdfce48dd57a7c3d8da6093d05c55fcc3f91b8e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/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)" || true
: "${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" -- "$@"