echo "$PROGRAM <--usage|--help|-?>"
echo " Prints this usage output and exits."
echo
- echo "$PROGRAM [--format <fmt>] [--prefix <path>] [--separate|-s] [output_file]"
+ echo "$PROGRAM [--format <fmt>] [--prefix <path>] [--verbose|-v] [--separate|-s] [output_file]"
echo " Creates an archive for the entire git superproject, and its submodules"
echo " using the passed parameters, described below."
echo
echo " If '--format' is specified, the archive is created with the named"
- echo " git archiver backend. Obviously, this must be a backend that git-archive"
+ echo " git archiver backend. Obviously, this must be a backend that git archive"
echo " understands. The format defaults to 'tar' if not specified."
echo
echo " If '--prefix' is specified, the archive's superproject and all submodules"
echo " Without this parameter or when combined with '--separate' the resulting"
echo " archive(s) are named with a dot-separated path of the archived directory and"
echo " a file extension equal to their format (e.g., 'superdir.submodule1dir.tar')."
+ echo
+ echo " If '--verbose' or '-v' is specified, progress will be printed."
}
function version () {
TOARCHIVE=`mktemp "$TMPDIR/$PROGRAM.toarchive.XXXXXX"`
OUT_FILE=$OLD_PWD # assume "this directory" without a name change by default
SEPARATE=0
+VERBOSE=0
FORMAT=tar
PREFIX=
exit
;;
+ --verbose | -v )
+ shift
+ VERBOSE=1
+ ;;
+
-? | --usage | --help )
usage
exit
if [ $SEPARATE -eq 1 -a ! -d $OUT_FILE ]; then
echo "When creating multiple archives, your destination must be a directory."
echo "If it's not, you risk being surprised when your files are overwritten."
- exit 1
+ exit
elif [ `git config -l | grep -q '^core\.bare=false'; echo $?` -ne 0 ]; then
echo "$PROGRAM must be run from a git working copy (i.e., not a bare repository)."
- exit 1
-elif ! git rev-parse HEAD &> /dev/null; then
- echo "You must have some commit in the git working copy."
- exit 1
+ exit
fi
# Create the superproject's git-archive
+if [ $VERBOSE -eq 1 ]; then
+ echo -n "creating superproject archive..."
+fi
git archive --format=$FORMAT --prefix="$PREFIX" $TREEISH > $TMPDIR/$(basename $(pwd)).$FORMAT
+if [ $VERBOSE -eq 1 ]; then
+ echo "done"
+fi
echo $TMPDIR/$(basename $(pwd)).$FORMAT >| $TMPFILE # clobber on purpose
superfile=`head -n 1 $TMPFILE`
-set +e
+if [ $VERBOSE -eq 1 ]; then
+ echo -n "looking for subprojects..."
+fi
# find all '.git' dirs, these show us the remaining to-be-archived dirs
-find . -name '.git' -type d -print | sed -e 's/^\.\///' -e 's/\.git$//' | grep -v '^$' >> $TOARCHIVE
-set -e
+# we only want directories that are below the current directory
+find . -mindepth 2 -name '.git' -type d -print | sed -e 's/^\.\///' -e 's/\.git$//' >> $TOARCHIVE
+# as of version 1.7.8, git places the submodule .git directories under the superprojects .git dir
+# the submodules get a .git file that points to their .git dir. we need to find all of these too
+find . -mindepth 2 -name '.git' -type f -print | xargs grep -l "gitdir" | sed -e 's/^\.\///' -e 's/\.git$//' >> $TOARCHIVE
+if [ $VERBOSE -eq 1 ]; then
+ echo "done"
+ echo " found:"
+ cat $TOARCHIVE | while read arch
+ do
+ echo " $arch"
+ done
+fi
+if [ $VERBOSE -eq 1 ]; then
+ echo -n "archiving submodules..."
+fi
while read path; do
- TREEISH=$(git submodule | grep "^ .*${path%/} " | cut -d ' ' -f 2) # git-submodule does not list trailing slashes in $path
+ TREEISH=$(git submodule | grep "^ .*${path%/} " | cut -d ' ' -f 2) # git submodule does not list trailing slashes in $path
cd "$path"
git archive --format=$FORMAT --prefix="${PREFIX}$path" ${TREEISH:-HEAD} > "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT
if [ $FORMAT == 'zip' ]; then
echo "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT >> $TMPFILE
cd "$OLD_PWD"
done < $TOARCHIVE
+if [ $VERBOSE -eq 1 ]; then
+ echo "done"
+fi
+
+if [ $VERBOSE -eq 1 ]; then
+ echo -n "concatenating archives into single archive..."
+fi
# Concatenate archives into a super-archive.
if [ $SEPARATE -eq 0 ]; then
if [ $FORMAT == 'tar' ]; then
echo "$superfile" >| $TMPFILE # clobber on purpose
fi
+if [ $VERBOSE -eq 1 ]; then
+ echo "done"
+fi
+if [ $VERBOSE -eq 1 ]; then
+ echo -n "moving archive to $OUT_FILE..."
+fi
while read file; do
mv "$file" "$OUT_FILE"
done < $TMPFILE
+if [ $VERBOSE -eq 1 ]; then
+ echo "done"
+fi