got git clone from git-remote-annex prototype working

eg git clone annex://`pwd` when the MANIFEST file is in the pwd.

This is easy in the prototype, just use $GIT_DIR, but in git-annex, it
will need to automatically git-annex init, and set up the special
remote, in order to be able to download the manifest and bundle keys
from it.

Sponsored-by: k0ld on Patreon
This commit is contained in:
Joey Hess 2024-04-30 14:40:05 -04:00
parent fc37243ffe
commit 7a9633312e
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -1,10 +1,11 @@
#!/bin/sh #!/bin/sh
URL="$2"
TOPDIR=.. TOPDIR="$(echo "$URL" | sed 's/^annex:\/\///')"
set -x set -x
rm -f .git/push-response rm -f $GIT_DIR/push-response
# Unfortunately, git bundle omits prerequisites that are omitted once, # Unfortunately, git bundle omits prerequisites that are omitted once,
# even if they are used by a later ref. # even if they are used by a later ref.
@ -43,7 +44,7 @@ while read foo; do
list*) list*)
if [ -e "$TOPDIR/MANIFEST" ]; then if [ -e "$TOPDIR/MANIFEST" ]; then
for f in $(cat $TOPDIR/MANIFEST); do for f in $(cat $TOPDIR/MANIFEST); do
git bundle list-heads $TOPDIR/$f >> .git/listed-refs-new git bundle list-heads $TOPDIR/$f >> $GIT_DIR/listed-refs-new
if [ "$foo" = "list for-push" ]; then if [ "$foo" = "list for-push" ]; then
# Get all the objects from the bundle. This is done here so that # Get all the objects from the bundle. This is done here so that
# refs/namespaces/mine can be updated with what was listed, # refs/namespaces/mine can be updated with what was listed,
@ -52,8 +53,8 @@ while read foo; do
git bundle unbundle "$TOPDIR/$f" >/dev/null 2>&1 git bundle unbundle "$TOPDIR/$f" >/dev/null 2>&1
fi fi
done done
perl -e 'while (<>) { if (m/(.*) (.*)/) { $seen{$2}=$1 } }; foreach my $k (keys %seen) { print "$seen{$k} $k\n" }' < .git/listed-refs-new > .git/listed-refs perl -e 'while (<>) { if (m/(.*) (.*)/) { $seen{$2}=$1 } }; foreach my $k (keys %seen) { print "$seen{$k} $k\n" }' < $GIT_DIR/listed-refs-new > $GIT_DIR/listed-refs
rm -f .git/listed-refs-new rm -f $GIT_DIR/listed-refs-new
# when listing for a push, update refs/namespaces/mine to match what was # when listing for a push, update refs/namespaces/mine to match what was
# listed. This is necessary in order for a full repush to know what to push. # listed. This is necessary in order for a full repush to know what to push.
@ -63,7 +64,7 @@ while read foo; do
done done
IFS=" IFS="
" "
for x in $(cat .git/listed-refs); do for x in $(cat $GIT_DIR/listed-refs); do
sha="$(echo "$x" | cut -d ' ' -f 1)" sha="$(echo "$x" | cut -d ' ' -f 1)"
r="$(echo "$x" | cut -d ' ' -f 2)" r="$(echo "$x" | cut -d ' ' -f 2)"
git update-ref "$r" "$sha" git update-ref "$r" "$sha"
@ -72,11 +73,11 @@ while read foo; do
fi fi
# respond to git with a list of refs # respond to git with a list of refs
sed 's/refs\/namespaces\/mine\///' .git/listed-refs sed 's/refs\/namespaces\/mine\///' $GIT_DIR/listed-refs
# .git/listed-refs is later checked in push # $GIT_DIR/listed-refs is later checked in push
else else
rm -f .git/listed-refs rm -f $GIT_DIR/listed-refs
touch .git/listed-refs touch $GIT_DIR/listed-refs
fi fi
echo echo
;; ;;
@ -107,28 +108,28 @@ while read foo; do
# all remaining refs. # all remaining refs.
REPUSH=1 REPUSH=1
git update-ref -d "$mydstref" git update-ref -d "$mydstref"
touch .git/push-response touch $GIT_DIR/push-response
echo "ok $dstref" >> .git/push-response echo "ok $dstref" >> $GIT_DIR/push-response
else else
if [ ! "$forcedpush" ]; then if [ ! "$forcedpush" ]; then
# check if the push would overwrite # check if the push would overwrite
# work in the ref currently stored in the # work in the ref currently stored in the
# remote, if so refuse to do it # remote, if so refuse to do it
prevsha=$(grep " $mydstref$" .git/listed-refs | awk '{print $1}') prevsha=$(grep " $mydstref$" $GIT_DIR/listed-refs | awk '{print $1}')
newsha=$(git rev-parse "$srcref") newsha=$(git rev-parse "$srcref")
if [ -n "$prevsha" ] && [ "$prevsha" != "$newsha" ] && [ -z "$(git log --oneline $prevsha..$newsha 2>/dev/null)" ]; then if [ -n "$prevsha" ] && [ "$prevsha" != "$newsha" ] && [ -z "$(git log --oneline $prevsha..$newsha 2>/dev/null)" ]; then
touch .git/push-response touch $GIT_DIR/push-response
echo "error $dstref non-fast-forward" >> .git/push-response echo "error $dstref non-fast-forward" >> $GIT_DIR/push-response
else else
touch .git/push-response touch $GIT_DIR/push-response
echo "ok $dstref" >> .git/push-response echo "ok $dstref" >> $GIT_DIR/push-response
git update-ref "$mydstref" "$srcref" git update-ref "$mydstref" "$srcref"
push_refs="$mydstref $push_refs" push_refs="$mydstref $push_refs"
fi fi
else else
git update-ref "$mydstref" "$srcref" git update-ref "$mydstref" "$srcref"
touch .git/push-response touch $GIT_DIR/push-response
echo "ok $dstref" >> .git/push-response echo "ok $dstref" >> $GIT_DIR/push-response
push_refs="$mydstref $push_refs" push_refs="$mydstref $push_refs"
fi fi
fi fi
@ -171,7 +172,7 @@ while read foo; do
# incremental bundle # incremental bundle
for r in $push_refs; do for r in $push_refs; do
newsha=$(git show-ref "$r" | awk '{print $1}') newsha=$(git show-ref "$r" | awk '{print $1}')
oldsha=$(grep " $r$" .git/listed-refs | awk '{print $1}') oldsha=$(grep " $r$" $GIT_DIR/listed-refs | awk '{print $1}')
if [ -n "$oldsha" ]; then if [ -n "$oldsha" ]; then
# include changes from $oldsha to $r when there are some # include changes from $oldsha to $r when there are some
if [ -n "$(git log --oneline $oldsha..$r)" ]; then if [ -n "$(git log --oneline $oldsha..$r)" ]; then
@ -194,15 +195,15 @@ while read foo; do
# and only including changes from them) # and only including changes from them)
echo "$r" echo "$r"
fi fi
done > .git/tobundle done > $GIT_DIR/tobundle
if [ -s ".git/tobundle" ]; then if [ -s "$GIT_DIR/tobundle" ]; then
git bundle create --quiet $TOPDIR/new.bundle --stdin < ".git/tobundle" git bundle create --quiet $TOPDIR/new.bundle --stdin < "$GIT_DIR/tobundle"
addnewbundle addnewbundle
fi fi
fi fi
fi fi
cat .git/push-response cat $GIT_DIR/push-response
rm -f .git/push-response rm -f $GIT_DIR/push-response
echo echo
dopush="" dopush=""
fi fi