blob: e44af2c86d8e7e44bc79aafcc8ccef3806804720 [file] [log] [blame]
Linus Torvalds7ef76922005-05-22 11:03:24 -07001#!/bin/sh
2#
freku045@student.liu.se87358b72005-12-13 23:30:31 +01003
4USAGE='<fetch-options> <repository> <refspec>...'
Junio C Hamano4da90282006-12-14 00:36:23 -08005SUBDIRECTORY_OK=Yes
Junio C Hamanoae2b0f12005-11-24 00:12:11 -08006. git-sh-setup
Shawn O. Pearcef9474132006-12-28 02:34:48 -05007set_reflog_action "fetch $*"
Junio C Hamano514c09f2007-01-12 12:49:05 -08008cd_to_toplevel ;# probably unnecessary...
Shawn O. Pearcef9474132006-12-28 02:34:48 -05009
Junio C Hamano215a7ad2005-09-07 17:26:23 -070010. git-parse-remote
Junio C Hamano853a3692005-08-20 02:54:34 -070011_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
12_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
Linus Torvaldsb33e9662005-07-08 10:57:21 -070013
Junio C Hamano221e7432005-10-10 23:22:02 -070014LF='
15'
16IFS="$LF"
17
Junio C Hamano03febf92006-01-07 00:48:04 -080018no_tags=
Linus Torvaldsed1aadf2005-09-29 14:35:15 -070019tags=
Junio C Hamano853a3692005-08-20 02:54:34 -070020append=
Junio C Hamanoae2da402005-08-22 21:28:33 -070021force=
Linus Torvalds583122c2005-11-18 08:31:55 -080022verbose=
Junio C Hamanob10ac502005-08-25 18:15:32 -070023update_head_ok=
Michal Ostrowski2c620a12006-01-20 13:05:24 -050024exec=
Nicolas Pitre920ccbf2006-11-01 17:06:22 -050025keep=
Johannes Schindelinf53514b2006-10-30 20:09:53 +010026shallow_depth=
Johannes Schindelin83a5ad62007-02-20 03:01:44 +010027no_progress=
28test -t 1 || no_progress=--no-progress
Junio C Hamanoa858c002007-02-25 13:13:17 -080029quiet=
David Kastrup822f7c72007-09-23 22:42:08 +020030while test $# != 0
Junio C Hamanoae2da402005-08-22 21:28:33 -070031do
32 case "$1" in
33 -a|--a|--ap|--app|--appe|--appen|--append)
34 append=t
Junio C Hamanoae2da402005-08-22 21:28:33 -070035 ;;
Junio C Hamano2796a9d2006-01-26 18:11:06 -080036 --upl|--uplo|--uploa|--upload|--upload-|--upload-p|\
37 --upload-pa|--upload-pac|--upload-pack)
Michal Ostrowski2c620a12006-01-20 13:05:24 -050038 shift
Junio C Hamanoae1dffc2007-01-23 00:51:53 -080039 exec="--upload-pack=$1"
40 ;;
41 --upl=*|--uplo=*|--uploa=*|--upload=*|\
42 --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
Shawn O. Pearce4a91a1f2007-01-30 13:11:49 -050043 exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
Junio C Hamanoae1dffc2007-01-23 00:51:53 -080044 shift
Michal Ostrowski2c620a12006-01-20 13:05:24 -050045 ;;
Junio C Hamanoae2da402005-08-22 21:28:33 -070046 -f|--f|--fo|--for|--forc|--force)
47 force=t
Junio C Hamanob10ac502005-08-25 18:15:32 -070048 ;;
Linus Torvaldsed1aadf2005-09-29 14:35:15 -070049 -t|--t|--ta|--tag|--tags)
50 tags=t
51 ;;
Junio C Hamano03febf92006-01-07 00:48:04 -080052 -n|--n|--no|--no-|--no-t|--no-ta|--no-tag|--no-tags)
53 no_tags=t
54 ;;
Junio C Hamanob10ac502005-08-25 18:15:32 -070055 -u|--u|--up|--upd|--upda|--updat|--update|--update-|--update-h|\
56 --update-he|--update-hea|--update-head|--update-head-|\
57 --update-head-o|--update-head-ok)
58 update_head_ok=t
Junio C Hamanoae2da402005-08-22 21:28:33 -070059 ;;
Junio C Hamanoa858c002007-02-25 13:13:17 -080060 -q|--q|--qu|--qui|--quie|--quiet)
61 quiet=--quiet
62 ;;
Linus Torvalds583122c2005-11-18 08:31:55 -080063 -v|--verbose)
Alex Riesen684f6742007-05-23 23:31:13 +020064 verbose="$verbose"Yes
Linus Torvalds583122c2005-11-18 08:31:55 -080065 ;;
Tom Prince0f76f522006-01-10 18:50:19 -070066 -k|--k|--ke|--kee|--keep)
Nicolas Pitre576162a2006-11-01 17:06:25 -050067 keep='-k -k'
Tom Prince0f76f522006-01-10 18:50:19 -070068 ;;
Johannes Schindelinf53514b2006-10-30 20:09:53 +010069 --depth=*)
70 shallow_depth="--depth=`expr "z$1" : 'z-[^=]*=\(.*\)'`"
71 ;;
72 --depth)
73 shift
74 shallow_depth="--depth=$1"
75 ;;
freku045@student.liu.se87358b72005-12-13 23:30:31 +010076 -*)
77 usage
78 ;;
Junio C Hamanoae2da402005-08-22 21:28:33 -070079 *)
80 break
81 ;;
82 esac
Junio C Hamanob10ac502005-08-25 18:15:32 -070083 shift
Junio C Hamanoae2da402005-08-22 21:28:33 -070084done
85
Junio C Hamano853a3692005-08-20 02:54:34 -070086case "$#" in
870)
Santi Béjar648ad182006-09-23 12:05:43 +020088 origin=$(get_default_remote)
89 test -n "$(get_remote_url ${origin})" ||
90 die "Where do you want to fetch from today?"
91 set x $origin ; shift ;;
Junio C Hamano853a3692005-08-20 02:54:34 -070092esac
Junio C Hamanoae2da402005-08-22 21:28:33 -070093
Uwe Kleine-König5dee29a2007-01-25 05:45:39 +010094if test -z "$exec"
95then
96 # No command line override and we have configuration for the remote.
97 exec="--upload-pack=$(get_uploadpack $1)"
98fi
99
Junio C Hamano853a3692005-08-20 02:54:34 -0700100remote_nick="$1"
101remote=$(get_remote_url "$@")
102refs=
103rref=
104rsync_slurped_objects=
Linus Torvalds7ef76922005-05-22 11:03:24 -0700105
Junio C Hamano853a3692005-08-20 02:54:34 -0700106if test "" = "$append"
107then
Santi_Béjardf342972005-10-05 18:58:10 +0200108 : >"$GIT_DIR/FETCH_HEAD"
Junio C Hamano853a3692005-08-20 02:54:34 -0700109fi
110
Junio C Hamano28b8e612006-11-22 21:57:14 -0800111# Global that is reused later
Junio C Hamanoae1dffc2007-01-23 00:51:53 -0800112ls_remote_result=$(git ls-remote $exec "$remote") ||
Nicolas Pitreb3d98992006-12-18 15:16:58 -0500113 die "Cannot get the repository state from $remote"
Junio C Hamano28b8e612006-11-22 21:57:14 -0800114
Junio C Hamano853a3692005-08-20 02:54:34 -0700115append_fetch_head () {
Junio C Hamanod4289ff2007-01-16 00:23:24 -0800116 flags=
Santi Béjar08727ea2007-03-19 00:16:23 +0100117 test -n "$verbose" && flags="$flags$LF-v"
118 test -n "$force$single_force" && flags="$flags$LF-f"
Junio C Hamanod4289ff2007-01-16 00:23:24 -0800119 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
Junio C Hamano5be60072007-07-02 22:52:14 -0700120 git fetch--tool $flags append-fetch-head "$@"
Junio C Hamano853a3692005-08-20 02:54:34 -0700121}
122
Junio C Hamano4b441f42007-01-07 02:17:52 -0800123# updating the current HEAD with git-fetch in a bare
124# repository is always fine.
125if test -z "$update_head_ok" && test $(is_bare_repository) = false
126then
Junio C Hamano5be60072007-07-02 22:52:14 -0700127 orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
Junio C Hamano4b441f42007-01-07 02:17:52 -0800128fi
Junio C Hamanob10ac502005-08-25 18:15:32 -0700129
Junio C Hamano24424fc2007-02-15 01:46:27 -0800130# Allow --notags from remote.$1.tagopt
131case "$tags$no_tags" in
132'')
Junio C Hamano5be60072007-07-02 22:52:14 -0700133 case "$(git config --get "remote.$1.tagopt")" in
Junio C Hamano24424fc2007-02-15 01:46:27 -0800134 --no-tags)
135 no_tags=t ;;
136 esac
137esac
138
Linus Torvaldsed1aadf2005-09-29 14:35:15 -0700139# If --tags (and later --heads or --all) is specified, then we are
140# not talking about defaults stored in Pull: line of remotes or
141# branches file, and just fetch those and refspecs explicitly given.
142# Otherwise we do what we always did.
143
144reflist=$(get_remote_refs_for_fetch "$@")
145if test "$tags"
146then
Junio C Hamanoed9f7c92006-12-17 17:57:19 -0800147 taglist=`IFS=' ' &&
Junio C Hamano28b8e612006-11-22 21:57:14 -0800148 echo "$ls_remote_result" |
Junio C Hamano5be60072007-07-02 22:52:14 -0700149 git show-ref --exclude-existing=refs/tags/ |
Junio C Hamano81214e42006-01-05 19:42:12 -0800150 while read sha1 name
151 do
Junio C Hamano85b1f982007-02-11 13:41:23 -0800152 echo ".${name}:${name}"
Junio C Hamano57a39692006-07-10 03:34:34 -0700153 done` || exit
Linus Torvaldsed1aadf2005-09-29 14:35:15 -0700154 if test "$#" -gt 1
155 then
156 # remote URL plus explicit refspecs; we need to merge them.
Junio C Hamano221e7432005-10-10 23:22:02 -0700157 reflist="$reflist$LF$taglist"
Linus Torvaldsed1aadf2005-09-29 14:35:15 -0700158 else
159 # No explicit refspecs; fetch tags only.
160 reflist=$taglist
161 fi
162fi
163
Paolo Bonzini9debc322007-03-15 09:23:20 +0100164fetch_all_at_once () {
Junio C Hamanob74e8cb2007-01-15 22:56:34 -0800165
Junio C Hamano5be60072007-07-02 22:52:14 -0700166 eval=$(echo "$1" | git fetch--tool parse-reflist "-")
Junio C Hamanod1e0ef62007-01-16 02:31:36 -0800167 eval "$eval"
Junio C Hamanob74e8cb2007-01-15 22:56:34 -0800168
169 ( : subshell because we muck with IFS
170 IFS=" $LF"
171 (
Paolo Bonzini9debc322007-03-15 09:23:20 +0100172 if test "$remote" = . ; then
Junio C Hamano5be60072007-07-02 22:52:14 -0700173 git show-ref $rref || echo failed "$remote"
Paolo Bonzini9debc322007-03-15 09:23:20 +0100174 elif test -f "$remote" ; then
Junio C Hamanoc1f50862007-03-14 01:40:19 -0700175 test -n "$shallow_depth" &&
176 die "shallow clone with bundle is not supported"
Junio C Hamano5be60072007-07-02 22:52:14 -0700177 git bundle unbundle "$remote" $rref ||
Junio C Hamanoc1f50862007-03-14 01:40:19 -0700178 echo failed "$remote"
179 else
Junio C Hamanoe3c6f242007-04-05 03:22:55 -0700180 if test -d "$remote" &&
181
182 # The remote might be our alternate. With
183 # this optimization we will bypass fetch-pack
184 # altogether, which means we cannot be doing
185 # the shallow stuff at all.
186 test ! -f "$GIT_DIR/shallow" &&
187 test -z "$shallow_depth" &&
188
189 # See if all of what we are going to fetch are
190 # connected to our repository's tips, in which
191 # case we do not have to do any fetch.
OGAWA Hirofumiafb5f392007-04-24 04:26:26 +0900192 theirs=$(echo "$ls_remote_result" | \
Junio C Hamano5be60072007-07-02 22:52:14 -0700193 git fetch--tool -s pick-rref "$rref" "-") &&
Junio C Hamanoe3c6f242007-04-05 03:22:55 -0700194
195 # This will barf when $theirs reach an object that
196 # we do not have in our repository. Otherwise,
197 # we already have everything the fetch would bring in.
Junio C Hamano5be60072007-07-02 22:52:14 -0700198 git rev-list --objects $theirs --not --all \
Junio C Hamanoe3c6f242007-04-05 03:22:55 -0700199 >/dev/null 2>/dev/null
200 then
OGAWA Hirofumiafb5f392007-04-24 04:26:26 +0900201 echo "$ls_remote_result" | \
Junio C Hamano5be60072007-07-02 22:52:14 -0700202 git fetch--tool pick-rref "$rref" "-"
Junio C Hamanoe3c6f242007-04-05 03:22:55 -0700203 else
Alex Riesen684f6742007-05-23 23:31:13 +0200204 flags=
205 case $verbose in
206 YesYes*)
207 flags="-v"
208 ;;
209 esac
Junio C Hamanoe3c6f242007-04-05 03:22:55 -0700210 git-fetch-pack --thin $exec $keep $shallow_depth \
Alex Riesen684f6742007-05-23 23:31:13 +0200211 $quiet $no_progress $flags "$remote" $rref ||
Junio C Hamanoe3c6f242007-04-05 03:22:55 -0700212 echo failed "$remote"
213 fi
Junio C Hamanoc1f50862007-03-14 01:40:19 -0700214 fi
Junio C Hamanob74e8cb2007-01-15 22:56:34 -0800215 ) |
216 (
Junio C Hamanofbe26872007-01-16 01:53:29 -0800217 flags=
218 test -n "$verbose" && flags="$flags -v"
219 test -n "$force" && flags="$flags -f"
220 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
Junio C Hamano5be60072007-07-02 22:52:14 -0700221 git fetch--tool $flags native-store \
Junio C Hamanofee7c2c2007-02-24 04:35:31 -0800222 "$remote" "$remote_nick" "$refs"
Junio C Hamanob74e8cb2007-01-15 22:56:34 -0800223 )
224 ) || exit
225
226}
227
Paolo Bonzini9debc322007-03-15 09:23:20 +0100228fetch_per_ref () {
Junio C Hamano03febf92006-01-07 00:48:04 -0800229 reflist="$1"
230 refs=
Santi Béjar4839bd82006-09-29 20:05:40 +0200231 rref=
Junio C Hamano853a3692005-08-20 02:54:34 -0700232
Junio C Hamano03febf92006-01-07 00:48:04 -0800233 for ref in $reflist
234 do
235 refs="$refs$LF$ref"
Junio C Hamano853a3692005-08-20 02:54:34 -0700236
Junio C Hamano03febf92006-01-07 00:48:04 -0800237 # These are relative path from $GIT_DIR, typically starting at refs/
238 # but may be HEAD
Mark Woodingf327dbc2006-04-13 22:01:24 +0000239 if expr "z$ref" : 'z\.' >/dev/null
Junio C Hamano03febf92006-01-07 00:48:04 -0800240 then
241 not_for_merge=t
Mark Woodingf327dbc2006-04-13 22:01:24 +0000242 ref=$(expr "z$ref" : 'z\.\(.*\)')
Junio C Hamano03febf92006-01-07 00:48:04 -0800243 else
244 not_for_merge=
245 fi
Junio C Hamanodfdcb552006-04-13 19:05:38 -0700246 if expr "z$ref" : 'z+' >/dev/null
Junio C Hamano03febf92006-01-07 00:48:04 -0800247 then
248 single_force=t
Junio C Hamanodfdcb552006-04-13 19:05:38 -0700249 ref=$(expr "z$ref" : 'z+\(.*\)')
Junio C Hamano03febf92006-01-07 00:48:04 -0800250 else
251 single_force=
252 fi
Mark Woodingf327dbc2006-04-13 22:01:24 +0000253 remote_name=$(expr "z$ref" : 'z\([^:]*\):')
254 local_name=$(expr "z$ref" : 'z[^:]*:\(.*\)')
Junio C Hamano853a3692005-08-20 02:54:34 -0700255
Junio C Hamano03febf92006-01-07 00:48:04 -0800256 rref="$rref$LF$remote_name"
Junio C Hamano4447bad2005-09-17 11:56:41 -0700257
Junio C Hamano03febf92006-01-07 00:48:04 -0800258 # There are transports that can fetch only one head at a time...
259 case "$remote" in
Sasha Khapyorsky38529e22006-09-14 05:24:04 +0300260 http://* | https://* | ftp://*)
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100261 test -n "$shallow_depth" &&
262 die "shallow clone with http not supported"
Tuncer Ayazddaf7312006-10-25 12:03:06 +0200263 proto=`expr "$remote" : '\([^:]*\):'`
Junio C Hamano03febf92006-01-07 00:48:04 -0800264 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
265 curl_extra_args="-k"
266 fi
Sasha Khapyorsky3ea099d2006-09-29 03:10:44 +0300267 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
Junio C Hamano5be60072007-07-02 22:52:14 -0700268 "`git config --bool http.noEPSV`" = true ]; then
Sasha Khapyorsky3ea099d2006-09-29 03:10:44 +0300269 noepsv_opt="--disable-epsv"
270 fi
Junio C Hamano2986c022006-11-22 22:24:09 -0800271
272 # Find $remote_name from ls-remote output.
OGAWA Hirofumiafb5f392007-04-24 04:26:26 +0900273 head=$(echo "$ls_remote_result" | \
Junio C Hamano5be60072007-07-02 22:52:14 -0700274 git fetch--tool -s pick-rref "$remote_name" "-")
Mark Woodingf327dbc2006-04-13 22:01:24 +0000275 expr "z$head" : "z$_x40\$" >/dev/null ||
Junio C Hamano2986c022006-11-22 22:24:09 -0800276 die "No such ref $remote_name at $remote"
Tuncer Ayazddaf7312006-10-25 12:03:06 +0200277 echo >&2 "Fetching $remote_name from $remote using $proto"
Junio C Hamanoa858c002007-02-25 13:13:17 -0800278 case "$quiet" in '') v=-v ;; *) v= ;; esac
Junio C Hamano27be4812007-04-08 23:27:22 -0700279 git-http-fetch $v -a "$head" "$remote" || exit
Junio C Hamano03febf92006-01-07 00:48:04 -0800280 ;;
281 rsync://*)
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100282 test -n "$shallow_depth" &&
283 die "shallow clone with rsync not supported"
Junio C Hamano03febf92006-01-07 00:48:04 -0800284 TMP_HEAD="$GIT_DIR/TMP_HEAD"
285 rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
Junio C Hamano5be60072007-07-02 22:52:14 -0700286 head=$(git rev-parse --verify TMP_HEAD)
Junio C Hamano03febf92006-01-07 00:48:04 -0800287 rm -f "$TMP_HEAD"
Junio C Hamanoa858c002007-02-25 13:13:17 -0800288 case "$quiet" in '') v=-v ;; *) v= ;; esac
Junio C Hamano03febf92006-01-07 00:48:04 -0800289 test "$rsync_slurped_objects" || {
Junio C Hamanoa858c002007-02-25 13:13:17 -0800290 rsync -a $v --ignore-existing --exclude info \
Junio C Hamano03febf92006-01-07 00:48:04 -0800291 "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit
Junio C Hamano853a3692005-08-20 02:54:34 -0700292
Junio C Hamano03febf92006-01-07 00:48:04 -0800293 # Look at objects/info/alternates for rsync -- http will
294 # support it natively and git native ones will do it on
295 # the remote end. Not having that file is not a crime.
296 rsync -q "$remote/objects/info/alternates" \
297 "$GIT_DIR/TMP_ALT" 2>/dev/null ||
298 rm -f "$GIT_DIR/TMP_ALT"
299 if test -f "$GIT_DIR/TMP_ALT"
300 then
301 resolve_alternates "$remote" <"$GIT_DIR/TMP_ALT" |
302 while read alt
303 do
304 case "$alt" in 'bad alternate: '*) die "$alt";; esac
305 echo >&2 "Getting alternate: $alt"
306 rsync -av --ignore-existing --exclude info \
307 "$alt" "$GIT_OBJECT_DIRECTORY/" || exit
308 done
309 rm -f "$GIT_DIR/TMP_ALT"
310 fi
311 rsync_slurped_objects=t
312 }
313 ;;
Junio C Hamano03febf92006-01-07 00:48:04 -0800314 esac
Junio C Hamano853a3692005-08-20 02:54:34 -0700315
Junio C Hamano03febf92006-01-07 00:48:04 -0800316 append_fetch_head "$head" "$remote" \
Junio C Hamanof64d7fd2006-11-25 01:04:28 -0800317 "$remote_name" "$remote_nick" "$local_name" "$not_for_merge" || exit
Junio C Hamano853a3692005-08-20 02:54:34 -0700318
Junio C Hamano03febf92006-01-07 00:48:04 -0800319 done
320
Junio C Hamanob74e8cb2007-01-15 22:56:34 -0800321}
Junio C Hamanoac9c1102007-01-01 12:24:15 -0800322
Junio C Hamanob74e8cb2007-01-15 22:56:34 -0800323fetch_main () {
324 case "$remote" in
325 http://* | https://* | ftp://* | rsync://* )
Paolo Bonzini9debc322007-03-15 09:23:20 +0100326 fetch_per_ref "$@"
Junio C Hamanob74e8cb2007-01-15 22:56:34 -0800327 ;;
328 *)
Paolo Bonzini9debc322007-03-15 09:23:20 +0100329 fetch_all_at_once "$@"
Junio C Hamanob74e8cb2007-01-15 22:56:34 -0800330 ;;
331 esac
Junio C Hamano03febf92006-01-07 00:48:04 -0800332}
333
Junio C Hamanof64d7fd2006-11-25 01:04:28 -0800334fetch_main "$reflist" || exit
Junio C Hamano03febf92006-01-07 00:48:04 -0800335
336# automated tag following
337case "$no_tags$tags" in
338'')
Junio C Hamano6dc78e62006-02-22 13:10:37 -0800339 case "$reflist" in
340 *:refs/*)
341 # effective only when we are following remote branch
342 # using local tracking branch.
Junio C Hamanoed9f7c92006-12-17 17:57:19 -0800343 taglist=$(IFS=' ' &&
Junio C Hamano28b8e612006-11-22 21:57:14 -0800344 echo "$ls_remote_result" |
Junio C Hamano5be60072007-07-02 22:52:14 -0700345 git show-ref --exclude-existing=refs/tags/ |
Junio C Hamano6dc78e62006-02-22 13:10:37 -0800346 while read sha1 name
347 do
Junio C Hamano5be60072007-07-02 22:52:14 -0700348 git cat-file -t "$sha1" >/dev/null 2>&1 || continue
Junio C Hamano6dc78e62006-02-22 13:10:37 -0800349 echo >&2 "Auto-following $name"
350 echo ".${name}:${name}"
351 done)
352 esac
Junio C Hamano03febf92006-01-07 00:48:04 -0800353 case "$taglist" in
354 '') ;;
355 ?*)
Alexandre Julliardd1586312006-11-24 15:59:12 +0100356 # do not deepen a shallow tree when following tags
357 shallow_depth=
Junio C Hamanof64d7fd2006-11-25 01:04:28 -0800358 fetch_main "$taglist" || exit ;;
Junio C Hamano03febf92006-01-07 00:48:04 -0800359 esac
Junio C Hamano853a3692005-08-20 02:54:34 -0700360esac
Junio C Hamanob10ac502005-08-25 18:15:32 -0700361
362# If the original head was empty (i.e. no "master" yet), or
363# if we were told not to worry, we do not have to check.
Junio C Hamano98617182006-10-10 22:29:02 -0700364case "$orig_head" in
365'')
Junio C Hamanob10ac502005-08-25 18:15:32 -0700366 ;;
Junio C Hamano98617182006-10-10 22:29:02 -0700367?*)
Junio C Hamano5be60072007-07-02 22:52:14 -0700368 curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
Junio C Hamanob10ac502005-08-25 18:15:32 -0700369 if test "$curr_head" != "$orig_head"
370 then
Junio C Hamano5be60072007-07-02 22:52:14 -0700371 git update-ref \
Shawn O. Pearcef9474132006-12-28 02:34:48 -0500372 -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \
Shawn Pearce55b78352006-07-10 23:38:35 -0400373 HEAD "$orig_head"
Junio C Hamanob10ac502005-08-25 18:15:32 -0700374 die "Cannot fetch into the current branch."
375 fi
376 ;;
377esac