#!/bin/sh
#
# copy-git-tree - copy all files known to git on current branch into another dir

set -eu

src="$1"
dst="$2"

tmp="$(mktemp)"
git --git-dir "${src}/.git" ls-tree head --name-only >"${tmp}"

while read -r path; do
  src_path="${src}/${path}"
  dst_path="${dst}/${path}"
  mkdir -p "$(dirname "${dst_path}")"
  cp "${src_path}" "${dst_path}"
done <"${tmp}"
rm "${tmp}"
