2021-02-24 15:26:48 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# USAGE:
|
|
|
|
# Working directory needs to be git repo
|
|
|
|
# call with name of directory you'd like to dump to
|
|
|
|
|
2021-02-24 20:57:35 +01:00
|
|
|
# if used with a web server, make sure to always server type text/plain
|
|
|
|
# or append .txt to fullpath
|
|
|
|
|
2021-02-24 15:26:48 +01:00
|
|
|
set -eu
|
|
|
|
|
|
|
|
DIR="/var/www/git-dump/$1"
|
|
|
|
|
|
|
|
files=`git ls-tree --full-tree -r --name-only HEAD`
|
|
|
|
|
|
|
|
rm -rf "$DIR"
|
|
|
|
|
|
|
|
echo "$files" | while IFS=$'\n' read -r f; do
|
|
|
|
subdir=`dirname $f`
|
|
|
|
fulldir="$DIR/$subdir"
|
|
|
|
mkdir -p "$fulldir"
|
2021-02-24 20:57:35 +01:00
|
|
|
fullpath="$DIR/$f"
|
2021-02-24 15:26:48 +01:00
|
|
|
git show HEAD:"$f" > "$fullpath"
|
|
|
|
if file "$fullpath" | grep -q "text"; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
echo "Binary file" > "$fullpath"
|
|
|
|
fi
|
|
|
|
done
|