Skip to content

Instantly share code, notes, and snippets.

@lorenzleutgeb
Last active May 7, 2024 14:14
Show Gist options
  • Save lorenzleutgeb/c098ceab6ecc30339adb16812f660591 to your computer and use it in GitHub Desktop.
Save lorenzleutgeb/c098ceab6ecc30339adb16812f660591 to your computer and use it in GitHub Desktop.
rad-alternate
#! /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