aboutsummaryrefslogtreecommitdiffstats
path: root/git-package
diff options
context:
space:
mode:
Diffstat (limited to 'git-package')
-rwxr-xr-xgit-package33
1 files changed, 33 insertions, 0 deletions
diff --git a/git-package b/git-package
new file mode 100755
index 0000000..4becad9
--- /dev/null
+++ b/git-package
@@ -0,0 +1,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)"
+: "${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" -- "$@"