Created
June 13, 2012 04:00
-
-
Save gnue/2921792 to your computer and use it in GitHub Desktop.
git に export サブコマンドを追加する(tgz, tb2, zip, ディレクトリ出力も簡単)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
die() { | |
echo "$1" 1>&2 | |
exit 1 | |
} | |
usage() { | |
die "Usage: $(basename $0) [-o outfile] <tree-ish> [<path>...]" | |
} | |
dir="${PWD##*/}" | |
while getopts "o:h" opts; do | |
case $opts in | |
o) shift; outfile=$OPTARG; shift;; | |
h) shift; usage;; | |
esac | |
done | |
[ -z "$outfile" ] && outfile="$dir.tgz" | |
[ -z "$1" ] && usage | |
subdir="$(basename ${outfile%.*})" | |
case "${outfile##*.}" in | |
tgz) git archive --prefix="$subdir/" --format=tar "$@" | gzip > "$outfile";; | |
tb2|tbz2) git archive --prefix="$subdir/" "$@" | bzip2 > "$outfile";; | |
zip) git archive --prefix="$subdir/" --format=zip -o "$outfile" "$@";; | |
*) git archive --prefix="${outfile##*/}/" --format=tar "$@" | tar -C "$(dirname "$outfile")" -xf -;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment