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) --- README.md | 2 ++ git-package | 33 +++++++++++++++++++++++++++++++++ git-package.1 | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100755 git-package create mode 100644 git-package.1 diff --git a/README.md b/README.md index 01de724..e0c670c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ personal use. - git-init-shared: Initialize a bare repo that multiple users have write access to. This uses `setfacl(1)` and thereby relies on ACL support. +- git-package: Create an archive of a named tree suitable for distribution. See + [`git-package(1)`](git-package.1). - git-sign-for-cgit: Generate a snapshot and store its signify signature for [`cgit`](https://git.zx2c4.com/cgit/about/) using [`git-notes(1)`](https://git-scm.com/docs/git-notes). 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" -- "$@" diff --git a/git-package.1 b/git-package.1 new file mode 100644 index 0000000..ac3e5cf --- /dev/null +++ b/git-package.1 @@ -0,0 +1,53 @@ +.Dd May 22, 2021 +.Dt GIT-PACKAGE 1 +.Os +.Sh NAME +.Nm git-package +.Nd create an archive of a named tree suitable for distribution +.Sh SYNOPSIS +.Nm git package +.Op Fl f Ar format +.Ar tree-ish +.Op Ar path... +.Sh DESCRIPTION +.Nm +creates an archive of a named tree (or specific paths within that tree, if +specified) that is suitable for distribution on the world wide web. +It saves the archive to +.Pa -. , +where +.Em name +is the title of the repository. +For supported archive formats, see +.Xr git-archive 1 . +A default archive format can be set via +.Xr git-config 1 , +using the +.Em package.format +option. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl f Ar format +The format to archive +.Ar tree-ish +as. +Defaults to +.Em package.format , +or tar.gz if unset. +.El +.Sh SEE ALSO +.Xr git 1 , +.Xr git-archive 1 , +.Xr git-config 1 +.Sh HISTORY +.Nm +was written due to the lack of a convenient tool to create release +archives for distribution. +.Xr git-archive 1 +was considered, but was found to be too burdensome to be deployed regularly. +.Sh AUTHORS +.An -nosplit +.Nm +was written by +.An Wolfgang Müller Aq Mt wolf@oriole.systems . -- cgit v1.2.3-2-gb3c3