Created
June 10, 2016 08:15
-
-
Save tknerr/622ef610bbcceccd4b6458f248019b06 to your computer and use it in GitHub Desktop.
Git remote helper to allow for `git clone symlink:///path/to/original/repo` which simply creates a symlink to the original repo
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/sh | |
# The script is called with `git-remote-<protocol> <remote_name> <remote_url>` | |
remote_name=$1 | |
remote_url=$2 | |
# The GIT_DIR is already created when this remote helper is run | |
original_repo=$(echo $remote_url | sed 's/^symlink:\/\///') | |
link_target=$(echo $GIT_DIR | sed 's/\/\.git$//') | |
# Everyting we echo to stderr is shown to the user. Let's us an alias for it | |
alias errcho='>&2 echo' | |
# Now simply replace the GIT_DIR with a symlink to the original repo | |
errcho "Symlinking to '$original_repo'..." | |
rm -rf $link_target | |
ln -sn $original_repo $link_target | |
# Finally, we have to speak just enough to let Git successfully continue. | |
# Usually we would receive commands for import / export / etc here, but | |
# sine we just symlinked to an existing repo there is nothing left to do. | |
while read line | |
do | |
case $line in | |
'') | |
exit ;; | |
*) | |
echo '' ;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment