Commit Diff


commit - dbb6cb75f2dc5793d36587dc947bd723aebee707
commit + 67f102f4cf2eb37b789b83a6b7b872985d58a984
blob - 16d91e8922bc0053e108455bfee8b13f70c34494
blob + f101338246fc4cee4a0d1e0cedc72b3e986e7d2b
--- Makefile
+++ Makefile
@@ -1,7 +1,7 @@
 .POSIX:
 PREFIX = /usr/local
 MANPREFIX = ${PREFIX}/man
-VERSION = 0.3
+VERSION = 0.4
 
 all:
 
blob - f70cd33f2fc7d3ec872405de6c75ceea2064cb7c
blob + 8c34af6bf9e5e9586555f3d7dc3c93549c24fad2
--- got-archive
+++ got-archive
@@ -8,24 +8,27 @@ die() {
 }
 
 usage() {
-	die 1 "Usage: got-archive [-sV] [-b branch/tag] [-o outdir] [-t tmpdir] repo"
+	die 1 "Usage: got-archive [-afsV] [-o outdir] [-t tmpdir] repo [ref...]"
 }
 
-args=$(getopt b:o:st:V $*)
+args=$(getopt afo:st:V $*)
 [ $? -ne 0 ] && usage
 
 set -- $args
 
 strip=0
-branch=
+force=0
 outdir=.
 tmpdir="/tmp/got-archive"
 
 while [ $# -ne 0 ]; do
 	case "$1" in
-	-b)
-		branch=$2
+	-a)
+		all=1
 		shift
+		;;
+	-f)
+		force=1
 		shift
 		;;
 	-o)
@@ -53,32 +56,50 @@ while [ $# -ne 0 ]; do
 	esac
 done
 
-[ $# -ne 1 ] && usage
+[ $# -lt 1 ] && usage
 
 repo=$1
 name=$(basename "$repo" .git)
-if [ "$strip" = 1 ]; then
-	ver=$(echo "$branch" | sed 's/^v//g')
-else
-	ver=$branch
-fi
-
+mkdir -p "$tmpdir"
+shift
 [ -d "$repo" ] || die 2 "Error: invalid repo: $repo"
 
-mkdir -p "$tmpdir"
+# $1 - ref
+# $2 - name
+gen() {
+	cdir="$tmpdir/$2"
+	tarfile="$outdir/$2.tgz"
 
-if [ "$branch" ]; then
-	cname="$name-$ver"
-	cdir="$tmpdir/$cname"
+	[ -e "$tarfile" ] && [ "$force" = 0 ] && return
+
 	rm -rf "$cdir"
-	got checkout -q -c "$branch" "$repo" "$cdir" || die 3 "Error: failed to checkout"
-else
-	cname="$name"
-	cdir="$tmpdir/$cname"
+	got checkout -q -c "$1" "$repo" "$cdir" || die 3 "Error: failed to checkout: $2"
+	rm -rf "$cdir/.got"
+	tar -czf "$tarfile" -C "$tmpdir" "$2" || die 4 "Error: failed to create tarball: $tarfile"
 	rm -rf "$cdir"
-	got checkout -q "$repo" "$cdir" || die 3 "Error: failed to checkout"
+}
+
+if [ "$all" = 1 ]; then
+	[ $# -ne 0 ] && die 1 "Error: Can't combine -a and explicit refs" 
+
+	tags=$(find "$repo/refs/tags" -type f -exec basename {} \; 2>/dev/null)
+	[ $? -ne 0 ] && die 5 "Error: no tags found"
+	set -- $tags
 fi
 
-rm -rf "$cdir/.got"
-tar -czf "$outdir/$cname.tgz" -C "$tmpdir" "$cname" || die 4 "Error: failed to create tarball"
-rm -rf "$cdir"
+mkdir -p "$outdir"
+
+if [ $# -gt 0 ]; then
+	while [ $# -ne 0 ]; do
+		if [ "$strip" = 1 ]; then
+			ref=$(echo "$1" | sed 's/^v//g')
+		else
+			ref=$1
+		fi
+		gen "$1" "$name-$ref"
+		shift
+	done
+else
+	gen "HEAD" "$name"
+fi
+
blob - 3567dcf2df596dea1c77f6199a104f66664d2159 (mode 755)
blob + /dev/null
--- got-archive-all
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/sh
-
-die() {
-	ec=$1
-	shift
-	echo "$@" >&2
-	exit "$ec"
-}
-
-usage() {
-	die 1 "Usage: got-archive-all [-fsV] [-o outdir] [-t tmpdir] prefix"
-}
-
-args=$(getopt fo:st:V $*)
-[ $? -ne 0 ] && usage
-
-set -- $args
-
-force=0
-outdir=.
-flags=
-while [ $# -ne 0 ]; do
-	case "$1" in
-	-f)
-		force=1
-		shift
-		;;
-	-o)
-		outdir=$2
-		flags="$flags -o $2"
-		shift
-		shift
-		;;
-	-s)
-		flags="$flags -s"
-		shift
-		;;
-	-t)
-		flags="$flags -t $2"
-		shift
-		shift
-		;;
-	-V)
-		echo "got-archive-all-@VERSION@"
-		exit 1
-		;;
-	--)
-		shift
-		break
-		;;
-	esac
-done
-
-[ $# -ne 1 ] && usage
-
-prefix=$1
-
-for repo in "$prefix"/*.git; do
-	[ -d "$repo/refs/tags" ] || continue
-
-	name=$(basename "$repo" .git)
-
-	for tag in "$repo"/refs/tags/*; do
-		tag=$(basename "$tag")
-		if  [ ! -e "$outdir/$name-$tag.tgz" ] || [ "$force" = 1 ]; then
-			got-archive $flags -b "$tag" "$repo"
-		fi
-	done
-done
blob - ade310647577a32a9c771e9b79ee7fd4b2ca9a34 (mode 644)
blob + /dev/null
--- got-archive-all.1
+++ /dev/null
@@ -1,63 +0,0 @@
-.\"
-.\" Copyright (c) 2023 Benjamin Stürz
-.\"
-.\" Permission to use, copy, modify, and distribute this software for any
-.\" purpose with or without fee is hereby granted, provided that the above
-.\" copyright notice and this permission notice appear in all copies.
-.\"
-.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-.\"
-.Dd $Mdocdate$
-.Dt GOT-ARCHIVE-ALL 1
-.Os
-.Sh NAME
-.Nm got-archive-all
-.Nd run got-archive(1) on all repositories
-.Sh SYNOPSIS
-.Nm got-archive-all
-.Op Fl fsV
-.Op Fl o Ar outdir
-.Op Fl t Ar tmpdir
-.Ar directory
-.Sh DESCRIPTION
-.Nm
-runs
-.Xr got-archive 1
-on all repositories in
-.Ar directory .
-.Pp
-The options are as follows:
-.Bl -tag -width -Ds
-.It Fl f
-Don't skip already existing tarballs.
-.It Fl o Ar outdir
-An existing directory in which the tarball will be created.
-By default, this will be the current working directory.
-.It Fl s
-Strip a preceding "v" from the
-.Ar branch/tag .
-.It Fl t Ar tmpdir
-A temporary directory used for the checkout.
-By default, this will be
-.Ar /tmp/got-archive .
-.It Fl V
-Print the version of got-archive(1) and exit.
-.Sh EXIT STATUS
-.Ex -std got-archive-all
-.Sh EXAMPLES
-Create tarballs for all repositories in
-.Pa /var/git
-and put them into
-.Pa /mnt .
-.Pp 
-.Dl $ got-archive-all -s -o /mnt /var/git
-.Sh SEE ALSO
-.Xr got-archive 1
-.Sh AUTHORS
-.An Benjamin Stürz Aq Mt benni@stuerz.xyz
blob - cb87696a1e81a2bf65ce8c198250812083fb8941
blob + 28bde960a6e6534c03a88a48f8b3bcd838331940
--- got-archive.1
+++ got-archive.1
@@ -20,28 +20,46 @@
 .Nm got-archive
 .Nd git-archive(1) clone for got-archive(1)
 .Sh SYNOPSIS
-.Nm got-archive
-.Op Fl sV
-.Op Fl b Ar branch/tag
+.Nm
+.Op Fl fs
 .Op Fl o Ar outdir
 .Op Fl t Ar tmpdir
 .Ar repo
+.Op Ar ref...
+.Nm
+.Fl a
+.Op Fl fs
+.Op Fl o Ar outdir
+.Op Fl t Ar tmpdir
+.Ar repo
+.Nm
+.Fl V
 .Sh DESCRIPTION
 .Nm
-is a small helper script for got(1) useful for creating tarballs of repositories.
+is a small helper script for got(1) that simplifies the creation of tarballs for repositories.
 .Pp
+A 
+.Ar ref
+can be
+.Dl - a commit hash,
+.Dl - a branch,
+.Dl - a tag,
+.Dl - or HEAD (refering to eg. master or main)
+.Pp
 The options are as follows:
 .Bl -tag -width -Ds
-.Ar branch/tag .
-.It Fl b Ar branch/tag
-Specify a branch or tag.
-By default, the default branch of the repository is selected (eg. master or main).
+.It Fl a
+Generate tarballs for all tags in
+.Ar repo .
+.It Fl f
+Overwrite existing tarballs.
 .It Fl o Ar outdir
 An existing directory in which the tarball will be created.
 By default, this will be the current working directory.
 .It Fl s
 Strip a preceding "v" from the
-.Ar branch/tag .
+.Ar ref .
+This is useful for tags that like v1.0.
 .It Fl t Ar tmpdir
 A temporary directory used for the checkout.
 By default, this will be
@@ -51,19 +69,22 @@ Print the version of got-archive(1) and exit.
 .Sh EXIT STATUS
 .Ex -std got-archive
 .Sh EXAMPLES
-Create a tarball for
+Create a tarball for the master/main branch of
 .Pa /var/git/example.git .
 .Pp
 .Dl $ got-archive /var/git/example.git
 .Pp
-Create a tarball for tag v1.0 of
+Generate tarballs for all tags of
 .Pa /var/git/example.git
-and put the resulting
-.Pa example-1.0.tgz
 into
 .Pa /mnt .
 .Pp
-.Dl $ got-archive -s -b v1.0 -o /mnt /var/git/example.git
+.Dl $ got-archive -a -o /mnt /var/git/example.git
+.Pp
+Generate tarballs for all tags in all repositories in
+.Pa /var/git .
+.Pp
+.Dl $ for r in /var/git/*.git; do got-archive -ao /mnt """$r"""; done
 .Sh SEE ALSO
 .Xr got 1 ,
 .Xr tar 1