Last active
September 16, 2024 02:33
-
-
Save iso2022jp/2acab64bca9b2a8b6d53e6eb9b2a7204 to your computer and use it in GitHub Desktop.
Copy a single file from the remote git registory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copy the single file from the remote git registory. | |
set -euo pipefail | |
if [[ $# -lt 3 ]]; then | |
echo "Usage: $0 <repos> <branch> <src> [<dest>]">&2 | |
exit 1; | |
fi | |
repos="$1" | |
branch="$2" | |
src="${3#/}" | |
dest="${4:-.}" | |
work="$(mktemp -d)" | |
git clone --depth=1 --branch="$branch" --filter=blob:none --no-checkout "$repos" "$work" | |
trap "rm -rf ${work@Q}" EXIT | |
( | |
cd "$work" | |
git sparse-checkout set --no-cone "/$src" | |
git checkout | |
) | |
cp "$work/$src" "$dest" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment