docker-git-bundle 727 Bytes
#!/bin/bash

set -e
url="$1"
bundle_file="$2"

shift 2

declare -a git_args

rm -rf /tmp/build
mkdir -p /tmp/build
if [[ -e $bundle_file ]]; then
	git clone --mirror --bare "$bundle_file" "/tmp/build/base.git"
	git_args+=(
		--reference "/tmp/build/base.git"
	)
	ls -l "$bundle_file"
fi
git clone --mirror --bare "${git_args[@]}" "$url" "/tmp/build/repo.git"
GIT_DIR="/tmp/build/repo.git" git bundle create "/tmp/build/new-bundle.git" --all

ls -l "/tmp/build/new-bundle.git"

cp -a "/tmp/build/new-bundle.git" "$bundle_file.tmp"
if [[ -e $bundle_file ]]; then
	chown --reference "$bundle_file" "$bundle_file.tmp"
	chmod --reference "$bundle_file" "$bundle_file.tmp"
fi
mv "$bundle_file.tmp" "$bundle_file"

rm -rf /tmp/build