Last active
May 7, 2024 14:14
-
-
Save lorenzleutgeb/c098ceab6ecc30339adb16812f660591 to your computer and use it in GitHub Desktop.
rad-alternate
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 | |
set -eu | |
REMOTE="rad" | |
ALTERNATES="$(git rev-parse --absolute-git-dir)/objects/info/alternates" | |
URI=$(git remote get-url "$REMOTE") | |
if [ "${URI:0:6}" != "rad://" ] | |
then | |
echo "URL for remote '$REMOTE' does not have expected prefix 'rad://'. Aborting." | |
exit 1 | |
fi | |
ID="${URI:6}" | |
DIR="${RAD_HOME:-$HOME/.radicle}/storage/${ID}/objects" | |
if [ ! -d "$DIR" ] | |
then | |
echo 'Directory '$DIR' is expected to exist, but does not. Aborting.' | |
exit 2 | |
fi | |
if [ -f "$ALTERNATES" ] | |
then | |
if ! diff -U3 --color=always --label expected <(echo "$DIR") --label actual "$ALTERNATES" | |
then | |
echo -e "\n${ALTERNATES} exists and has unexpected contents. Aborting." | |
exit 3 | |
fi | |
else | |
echo "$DIR" > "$ALTERNATES" | |
fi | |
git count-objects -v | grep alternate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment