diff options
author | Wolfgang Müller | 2021-05-22 12:54:18 +0200 |
---|---|---|
committer | Wolfgang Müller | 2021-05-22 12:54:18 +0200 |
commit | 8643238ec04da8d0bda46cb06ecd29dc88f9d243 (patch) | |
tree | e43ab9adb83bde8ac2f51a80eabbf91d421f72e8 /git-package | |
parent | b4bcd4e667ae767b3736494b188523a5590b7f26 (diff) | |
download | git-helpers-8643238ec04da8d0bda46cb06ecd29dc88f9d243.tar.gz |
Add git-package(1)
Diffstat (limited to 'git-package')
-rwxr-xr-x | git-package | 33 |
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" -- "$@" |