Allow the user to control the verbosity of merge-recursive.
[gitweb.git] / git-fetch.sh
index 8bd11f8b60c0ffec8a67f59bc7e12e1f63adfc91..87b940b85b5b128f29dc6084bb545640e5bf6b92 100755 (executable)
@@ -5,12 +5,8 @@ USAGE='<fetch-options> <repository> <refspec>...'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 set_reflog_action "fetch $*"
+cd_to_toplevel ;# probably unnecessary...
 
-TOP=$(git-rev-parse --show-cdup)
-if test ! -z "$TOP"
-then
-       cd "$TOP"
-fi
 . git-parse-remote
 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
@@ -231,11 +227,12 @@ update_local_ref () {
     esac
 }
 
-case "$update_head_ok" in
-'')
+# updating the current HEAD with git-fetch in a bare
+# repository is always fine.
+if test -z "$update_head_ok" && test $(is_bare_repository) = false
+then
        orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
-       ;;
-esac
+fi
 
 # If --tags (and later --heads or --all) is specified, then we are
 # not talking about defaults stored in Pull: line of remotes or
@@ -382,13 +379,22 @@ fetch_main () {
       ;; # we are already done.
   *)
     ( : subshell because we muck with IFS
-      pack_lockfile=
       IFS="    $LF"
       (
-         git-fetch-pack --thin $exec $keep $shallow_depth "$remote" $rref || echo failed "$remote"
+         git-fetch-pack --thin $exec $keep $shallow_depth "$remote" $rref ||
+         echo failed "$remote"
       ) |
-      while read sha1 remote_name
-      do
+      (
+       trap '
+               if test -n "$keepfile" && test -f "$keepfile"
+               then
+                       rm -f "$keepfile"
+               fi
+       ' 0
+
+        keepfile=
+       while read sha1 remote_name
+       do
          case "$sha1" in
          failed)
                  echo >&2 "Fetch failure: $remote"
@@ -397,7 +403,7 @@ fetch_main () {
          pack)
                  continue ;;
          keep)
-                 pack_lockfile="$GIT_OBJECT_DIRECTORY/pack/pack-$remote_name.keep"
+                 keepfile="$GIT_OBJECT_DIRECTORY/pack/pack-$remote_name.keep"
                  continue ;;
          esac
          found=
@@ -429,8 +435,8 @@ fetch_main () {
          append_fetch_head "$sha1" "$remote" \
                  "$remote_name" "$remote_nick" "$local_name" \
                  "$not_for_merge" || exit
-      done &&
-      if [ "$pack_lockfile" ]; then rm -f "$pack_lockfile"; fi
+        done
+      )
     ) || exit ;;
   esac