[PATCH] Improve git-update-index error reporting
[git.git] / git-fetch.sh
index 4928cd5..72f17ab 100755 (executable)
@@ -94,6 +94,7 @@ append_fetch_head () {
 }
 
 fast_forward_local () {
+    mkdir -p "$(dirname "$GIT_DIR/$1")"
     case "$1" in
     refs/tags/*)
        # Tags need not be pointing at commits so there
@@ -182,12 +183,30 @@ do
        ;;
     rsync://*)
        TMP_HEAD="$GIT_DIR/TMP_HEAD"
-       rsync -L "$remote/$remote_name" "$TMP_HEAD" || exit 1
+       rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
        head=$(git-rev-parse TMP_HEAD)
        rm -f "$TMP_HEAD"
        test "$rsync_slurped_objects" || {
-           rsync -avz --ignore-existing "$remote/objects/" \
-               "$GIT_OBJECT_DIRECTORY/" || exit
+           rsync -av --ignore-existing --exclude info \
+               "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit
+
+           # Look at objects/info/alternates for rsync -- http will
+           # support it natively and git native ones will do it on the remote
+           # end.  Not having that file is not a crime.
+           rsync -q "$remote/objects/info/alternates" "$GIT_DIR/TMP_ALT" ||
+                   rm -f "$GIT_DIR/TMP_ALT"
+           if test -f "$GIT_DIR/TMP_ALT"
+           then
+               resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |
+               while read alt
+               do
+                   case "$alt" in 'bad alternate: '*) die "$alt";; esac
+                   echo >&2 "Getting alternate: $alt"
+                   rsync -av --ignore-existing --exclude info \
+                   "$alt" "$GIT_OBJECT_DIRECTORY/" || exit
+               done
+               rm -f "$GIT_DIR/TMP_ALT"
+           fi
            rsync_slurped_objects=t
        }
        ;;
@@ -204,9 +223,16 @@ case "$remote" in
 http://* | https://* | rsync://* )
     ;; # we are already done.
 *)
-    git-fetch-pack "$remote" $rref |
+    (
+       git-fetch-pack "$remote" $rref || echo failed "$remote"
+    ) |
     while read sha1 remote_name
     do
+       case "$sha1" in
+       failed)
+               echo >&2 "Fetch failure: $remote"
+               exit 1 ;;
+       esac
        found=
        single_force=
        for ref in $refs
@@ -224,7 +250,7 @@ http://* | https://* | rsync://* )
 
        local_name=$(expr "$found" : '[^:]*:\(.*\)')
        append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"
-    done
+    done || exit
     ;;
 esac