Skip to content

Instantly share code, notes, and snippets.

@drench
Created April 23, 2010 11:38
Show Gist options
  • Save drench/376455 to your computer and use it in GitHub Desktop.
Save drench/376455 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Tweaked from http://jeetworks.org/node/68 to remove bashisms.
# Drop this in your libexec/git-core/ to use it as "git targz"
if [ -z "$1" ]
then
echo "Usage: git-targz [rev] path"
echo
echo "Creates gzipped-compressed tarball archive of the current or specified branch."
exit 1
fi
if [ "$#" = "1" ]
then
path=$1
rev="HEAD"
else
rev=$1
path=$2
fi
basepath=`basename $path`
prefix=${basepath%%.*}
git archive --format=tar --prefix=$prefix/ $rev | gzip >$path
@timabell
Copy link

@drench
Copy link
Author

drench commented May 12, 2011

Generating the filename with "git describe" is nice. But why "/bin/bash"? The only reason I wrote this modification is because the original was unnecessarily bash-only. Yours works fine for me under /bin/sh on FreeBSD.

@timabell
Copy link

never thought to much about bash vs sh. I guess it's just habit. I've changed it for you :-) thanks for testing it.
I think that ubuntu that i use runs dash anyway...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment