Created
September 28, 2020 11:37
-
-
Save evansd/5193be7fd5621566858226a6cf44dc2d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
set -eo pipefail | |
this_dir="$( unset CDPATH && cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
: ${GIT_DIR="$this_dir/shared-git-repo"} | |
remote="$1" | |
sha="$2" | |
local_path="$3" | |
if [[ -z "$remote" || -z "$sha" || -z "$local_path" ]]; then | |
echo 'Usage: fetch-commit REMOTE SHA LOCAL_PATH' >&2 | |
echo >&2 | |
echo 'Fetch commit referenced by SHA from REMOTE and check it out in LOCAL_PATH' >&2 | |
exit 1 | |
fi | |
export GIT_DIR | |
mkdir -p "$GIT_DIR" | |
git init --bare --quiet | |
if ! git cat-file -e "$sha^{commit}" 2>/dev/null; then | |
echo "Fetching commit $sha from $remote" >&2 | |
git fetch --depth 1 --force "$remote" "$sha" | |
else | |
echo "Commit $sha already downloaded" >&2 | |
fi | |
mkdir -p "$local_path" | |
git --work-tree="$local_path" checkout --quiet --force "$sha" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment