Skip to content

Instantly share code, notes, and snippets.

@benjamin-asdf
Last active March 24, 2023 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjamin-asdf/37e0b30f93ecdb73e59c960297067662 to your computer and use it in GitHub Desktop.
Save benjamin-asdf/37e0b30f93ecdb73e59c960297067662 to your computer and use it in GitHub Desktop.
Pull gitlibs like clj cli does it. Helps to pull in git deps in a sort of immutable spirit, if you have another ref, it pulls the other ref next to the existing one.
#!/bin/sh
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <git-repo> <ref>"
exit 1
fi
repo=$(echo $1 | sed -e 's/.*\///' -e 's/\.git$//')
mkdir -p .gitlibs/
if [ ! -d .gitlibs/$repo ]; then
git clone --quiet --mirror $1 .gitlibs/$repo
fi
if [ ! -d .gitlibs/$repo/$2 ]; then
git --git-dir .gitlibs/$repo worktree add --force --detach .gitlibs/$repo/$2 $2
fi
echo .gitlibs/$repo/$2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment