From 8643238ec04da8d0bda46cb06ecd29dc88f9d243 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Sat, 22 May 2021 12:54:18 +0200 Subject: Add git-package(1) --- git-package | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 git-package (limited to 'git-package') 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" -- "$@" -- cgit v1.2.3-2-gb3c3