Linus Torvalds | 7ef7692 | 2005-05-22 11:03:24 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
freku045@student.liu.se | 87358b7 | 2005-12-13 23:30:31 +0100 | [diff] [blame] | 3 | |
| 4 | USAGE='<fetch-options> <repository> <refspec>...' |
Junio C Hamano | 4da9028 | 2006-12-14 00:36:23 -0800 | [diff] [blame] | 5 | SUBDIRECTORY_OK=Yes |
Junio C Hamano | ae2b0f1 | 2005-11-24 00:12:11 -0800 | [diff] [blame] | 6 | . git-sh-setup |
Shawn O. Pearce | f947413 | 2006-12-28 02:34:48 -0500 | [diff] [blame] | 7 | set_reflog_action "fetch $*" |
Junio C Hamano | 514c09f | 2007-01-12 12:49:05 -0800 | [diff] [blame] | 8 | cd_to_toplevel ;# probably unnecessary... |
Shawn O. Pearce | f947413 | 2006-12-28 02:34:48 -0500 | [diff] [blame] | 9 | |
Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 10 | . git-parse-remote |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 11 | _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 Torvalds | b33e966 | 2005-07-08 10:57:21 -0700 | [diff] [blame] | 13 | |
Junio C Hamano | 221e743 | 2005-10-10 23:22:02 -0700 | [diff] [blame] | 14 | LF=' |
| 15 | ' |
| 16 | IFS="$LF" |
| 17 | |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 18 | no_tags= |
Linus Torvalds | ed1aadf | 2005-09-29 14:35:15 -0700 | [diff] [blame] | 19 | tags= |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 20 | append= |
Junio C Hamano | ae2da40 | 2005-08-22 21:28:33 -0700 | [diff] [blame] | 21 | force= |
Linus Torvalds | 583122c | 2005-11-18 08:31:55 -0800 | [diff] [blame] | 22 | verbose= |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 23 | update_head_ok= |
Michal Ostrowski | 2c620a1 | 2006-01-20 13:05:24 -0500 | [diff] [blame] | 24 | exec= |
Nicolas Pitre | 920ccbf | 2006-11-01 17:06:22 -0500 | [diff] [blame] | 25 | keep= |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 26 | shallow_depth= |
Johannes Schindelin | 83a5ad6 | 2007-02-20 03:01:44 +0100 | [diff] [blame] | 27 | no_progress= |
| 28 | test -t 1 || no_progress=--no-progress |
Junio C Hamano | a858c00 | 2007-02-25 13:13:17 -0800 | [diff] [blame] | 29 | quiet= |
David Kastrup | 822f7c7 | 2007-09-23 22:42:08 +0200 | [diff] [blame] | 30 | while test $# != 0 |
Junio C Hamano | ae2da40 | 2005-08-22 21:28:33 -0700 | [diff] [blame] | 31 | do |
| 32 | case "$1" in |
| 33 | -a|--a|--ap|--app|--appe|--appen|--append) |
| 34 | append=t |
Junio C Hamano | ae2da40 | 2005-08-22 21:28:33 -0700 | [diff] [blame] | 35 | ;; |
Junio C Hamano | 2796a9d | 2006-01-26 18:11:06 -0800 | [diff] [blame] | 36 | --upl|--uplo|--uploa|--upload|--upload-|--upload-p|\ |
| 37 | --upload-pa|--upload-pac|--upload-pack) |
Michal Ostrowski | 2c620a1 | 2006-01-20 13:05:24 -0500 | [diff] [blame] | 38 | shift |
Junio C Hamano | ae1dffc | 2007-01-23 00:51:53 -0800 | [diff] [blame] | 39 | exec="--upload-pack=$1" |
| 40 | ;; |
| 41 | --upl=*|--uplo=*|--uploa=*|--upload=*|\ |
| 42 | --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*) |
Shawn O. Pearce | 4a91a1f | 2007-01-30 13:11:49 -0500 | [diff] [blame] | 43 | exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)') |
Junio C Hamano | ae1dffc | 2007-01-23 00:51:53 -0800 | [diff] [blame] | 44 | shift |
Michal Ostrowski | 2c620a1 | 2006-01-20 13:05:24 -0500 | [diff] [blame] | 45 | ;; |
Junio C Hamano | ae2da40 | 2005-08-22 21:28:33 -0700 | [diff] [blame] | 46 | -f|--f|--fo|--for|--forc|--force) |
| 47 | force=t |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 48 | ;; |
Linus Torvalds | ed1aadf | 2005-09-29 14:35:15 -0700 | [diff] [blame] | 49 | -t|--t|--ta|--tag|--tags) |
| 50 | tags=t |
| 51 | ;; |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 52 | -n|--n|--no|--no-|--no-t|--no-ta|--no-tag|--no-tags) |
| 53 | no_tags=t |
| 54 | ;; |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 55 | -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 Hamano | ae2da40 | 2005-08-22 21:28:33 -0700 | [diff] [blame] | 59 | ;; |
Junio C Hamano | a858c00 | 2007-02-25 13:13:17 -0800 | [diff] [blame] | 60 | -q|--q|--qu|--qui|--quie|--quiet) |
| 61 | quiet=--quiet |
| 62 | ;; |
Linus Torvalds | 583122c | 2005-11-18 08:31:55 -0800 | [diff] [blame] | 63 | -v|--verbose) |
Alex Riesen | 684f674 | 2007-05-23 23:31:13 +0200 | [diff] [blame] | 64 | verbose="$verbose"Yes |
Linus Torvalds | 583122c | 2005-11-18 08:31:55 -0800 | [diff] [blame] | 65 | ;; |
Tom Prince | 0f76f52 | 2006-01-10 18:50:19 -0700 | [diff] [blame] | 66 | -k|--k|--ke|--kee|--keep) |
Nicolas Pitre | 576162a | 2006-11-01 17:06:25 -0500 | [diff] [blame] | 67 | keep='-k -k' |
Tom Prince | 0f76f52 | 2006-01-10 18:50:19 -0700 | [diff] [blame] | 68 | ;; |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 69 | --depth=*) |
| 70 | shallow_depth="--depth=`expr "z$1" : 'z-[^=]*=\(.*\)'`" |
| 71 | ;; |
| 72 | --depth) |
| 73 | shift |
| 74 | shallow_depth="--depth=$1" |
| 75 | ;; |
freku045@student.liu.se | 87358b7 | 2005-12-13 23:30:31 +0100 | [diff] [blame] | 76 | -*) |
| 77 | usage |
| 78 | ;; |
Junio C Hamano | ae2da40 | 2005-08-22 21:28:33 -0700 | [diff] [blame] | 79 | *) |
| 80 | break |
| 81 | ;; |
| 82 | esac |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 83 | shift |
Junio C Hamano | ae2da40 | 2005-08-22 21:28:33 -0700 | [diff] [blame] | 84 | done |
| 85 | |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 86 | case "$#" in |
| 87 | 0) |
Santi Béjar | 648ad18 | 2006-09-23 12:05:43 +0200 | [diff] [blame] | 88 | 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 Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 92 | esac |
Junio C Hamano | ae2da40 | 2005-08-22 21:28:33 -0700 | [diff] [blame] | 93 | |
Uwe Kleine-König | 5dee29a | 2007-01-25 05:45:39 +0100 | [diff] [blame] | 94 | if test -z "$exec" |
| 95 | then |
| 96 | # No command line override and we have configuration for the remote. |
| 97 | exec="--upload-pack=$(get_uploadpack $1)" |
| 98 | fi |
| 99 | |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 100 | remote_nick="$1" |
| 101 | remote=$(get_remote_url "$@") |
| 102 | refs= |
| 103 | rref= |
| 104 | rsync_slurped_objects= |
Linus Torvalds | 7ef7692 | 2005-05-22 11:03:24 -0700 | [diff] [blame] | 105 | |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 106 | if test "" = "$append" |
| 107 | then |
Santi_Béjar | df34297 | 2005-10-05 18:58:10 +0200 | [diff] [blame] | 108 | : >"$GIT_DIR/FETCH_HEAD" |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 109 | fi |
| 110 | |
Junio C Hamano | 28b8e61 | 2006-11-22 21:57:14 -0800 | [diff] [blame] | 111 | # Global that is reused later |
Junio C Hamano | ae1dffc | 2007-01-23 00:51:53 -0800 | [diff] [blame] | 112 | ls_remote_result=$(git ls-remote $exec "$remote") || |
Nicolas Pitre | b3d9899 | 2006-12-18 15:16:58 -0500 | [diff] [blame] | 113 | die "Cannot get the repository state from $remote" |
Junio C Hamano | 28b8e61 | 2006-11-22 21:57:14 -0800 | [diff] [blame] | 114 | |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 115 | append_fetch_head () { |
Junio C Hamano | d4289ff | 2007-01-16 00:23:24 -0800 | [diff] [blame] | 116 | flags= |
Santi Béjar | 08727ea | 2007-03-19 00:16:23 +0100 | [diff] [blame] | 117 | test -n "$verbose" && flags="$flags$LF-v" |
| 118 | test -n "$force$single_force" && flags="$flags$LF-f" |
Junio C Hamano | d4289ff | 2007-01-16 00:23:24 -0800 | [diff] [blame] | 119 | GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 120 | git fetch--tool $flags append-fetch-head "$@" |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Junio C Hamano | 4b441f4 | 2007-01-07 02:17:52 -0800 | [diff] [blame] | 123 | # updating the current HEAD with git-fetch in a bare |
| 124 | # repository is always fine. |
| 125 | if test -z "$update_head_ok" && test $(is_bare_repository) = false |
| 126 | then |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 127 | orig_head=$(git rev-parse --verify HEAD 2>/dev/null) |
Junio C Hamano | 4b441f4 | 2007-01-07 02:17:52 -0800 | [diff] [blame] | 128 | fi |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 129 | |
Junio C Hamano | 24424fc | 2007-02-15 01:46:27 -0800 | [diff] [blame] | 130 | # Allow --notags from remote.$1.tagopt |
| 131 | case "$tags$no_tags" in |
| 132 | '') |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 133 | case "$(git config --get "remote.$1.tagopt")" in |
Junio C Hamano | 24424fc | 2007-02-15 01:46:27 -0800 | [diff] [blame] | 134 | --no-tags) |
| 135 | no_tags=t ;; |
| 136 | esac |
| 137 | esac |
| 138 | |
Linus Torvalds | ed1aadf | 2005-09-29 14:35:15 -0700 | [diff] [blame] | 139 | # 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 | |
| 144 | reflist=$(get_remote_refs_for_fetch "$@") |
| 145 | if test "$tags" |
| 146 | then |
Junio C Hamano | ed9f7c9 | 2006-12-17 17:57:19 -0800 | [diff] [blame] | 147 | taglist=`IFS=' ' && |
Junio C Hamano | 28b8e61 | 2006-11-22 21:57:14 -0800 | [diff] [blame] | 148 | echo "$ls_remote_result" | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 149 | git show-ref --exclude-existing=refs/tags/ | |
Junio C Hamano | 81214e4 | 2006-01-05 19:42:12 -0800 | [diff] [blame] | 150 | while read sha1 name |
| 151 | do |
Junio C Hamano | 85b1f98 | 2007-02-11 13:41:23 -0800 | [diff] [blame] | 152 | echo ".${name}:${name}" |
Junio C Hamano | 57a3969 | 2006-07-10 03:34:34 -0700 | [diff] [blame] | 153 | done` || exit |
Linus Torvalds | ed1aadf | 2005-09-29 14:35:15 -0700 | [diff] [blame] | 154 | if test "$#" -gt 1 |
| 155 | then |
| 156 | # remote URL plus explicit refspecs; we need to merge them. |
Junio C Hamano | 221e743 | 2005-10-10 23:22:02 -0700 | [diff] [blame] | 157 | reflist="$reflist$LF$taglist" |
Linus Torvalds | ed1aadf | 2005-09-29 14:35:15 -0700 | [diff] [blame] | 158 | else |
| 159 | # No explicit refspecs; fetch tags only. |
| 160 | reflist=$taglist |
| 161 | fi |
| 162 | fi |
| 163 | |
Paolo Bonzini | 9debc32 | 2007-03-15 09:23:20 +0100 | [diff] [blame] | 164 | fetch_all_at_once () { |
Junio C Hamano | b74e8cb | 2007-01-15 22:56:34 -0800 | [diff] [blame] | 165 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 166 | eval=$(echo "$1" | git fetch--tool parse-reflist "-") |
Junio C Hamano | d1e0ef6 | 2007-01-16 02:31:36 -0800 | [diff] [blame] | 167 | eval "$eval" |
Junio C Hamano | b74e8cb | 2007-01-15 22:56:34 -0800 | [diff] [blame] | 168 | |
| 169 | ( : subshell because we muck with IFS |
| 170 | IFS=" $LF" |
| 171 | ( |
Paolo Bonzini | 9debc32 | 2007-03-15 09:23:20 +0100 | [diff] [blame] | 172 | if test "$remote" = . ; then |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 173 | git show-ref $rref || echo failed "$remote" |
Paolo Bonzini | 9debc32 | 2007-03-15 09:23:20 +0100 | [diff] [blame] | 174 | elif test -f "$remote" ; then |
Junio C Hamano | c1f5086 | 2007-03-14 01:40:19 -0700 | [diff] [blame] | 175 | test -n "$shallow_depth" && |
| 176 | die "shallow clone with bundle is not supported" |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 177 | git bundle unbundle "$remote" $rref || |
Junio C Hamano | c1f5086 | 2007-03-14 01:40:19 -0700 | [diff] [blame] | 178 | echo failed "$remote" |
| 179 | else |
Junio C Hamano | e3c6f24 | 2007-04-05 03:22:55 -0700 | [diff] [blame] | 180 | 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 Hirofumi | afb5f39 | 2007-04-24 04:26:26 +0900 | [diff] [blame] | 192 | theirs=$(echo "$ls_remote_result" | \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 193 | git fetch--tool -s pick-rref "$rref" "-") && |
Junio C Hamano | e3c6f24 | 2007-04-05 03:22:55 -0700 | [diff] [blame] | 194 | |
| 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 Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 198 | git rev-list --objects $theirs --not --all \ |
Junio C Hamano | e3c6f24 | 2007-04-05 03:22:55 -0700 | [diff] [blame] | 199 | >/dev/null 2>/dev/null |
| 200 | then |
OGAWA Hirofumi | afb5f39 | 2007-04-24 04:26:26 +0900 | [diff] [blame] | 201 | echo "$ls_remote_result" | \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 202 | git fetch--tool pick-rref "$rref" "-" |
Junio C Hamano | e3c6f24 | 2007-04-05 03:22:55 -0700 | [diff] [blame] | 203 | else |
Alex Riesen | 684f674 | 2007-05-23 23:31:13 +0200 | [diff] [blame] | 204 | flags= |
| 205 | case $verbose in |
| 206 | YesYes*) |
| 207 | flags="-v" |
| 208 | ;; |
| 209 | esac |
Junio C Hamano | e3c6f24 | 2007-04-05 03:22:55 -0700 | [diff] [blame] | 210 | git-fetch-pack --thin $exec $keep $shallow_depth \ |
Alex Riesen | 684f674 | 2007-05-23 23:31:13 +0200 | [diff] [blame] | 211 | $quiet $no_progress $flags "$remote" $rref || |
Junio C Hamano | e3c6f24 | 2007-04-05 03:22:55 -0700 | [diff] [blame] | 212 | echo failed "$remote" |
| 213 | fi |
Junio C Hamano | c1f5086 | 2007-03-14 01:40:19 -0700 | [diff] [blame] | 214 | fi |
Junio C Hamano | b74e8cb | 2007-01-15 22:56:34 -0800 | [diff] [blame] | 215 | ) | |
| 216 | ( |
Junio C Hamano | fbe2687 | 2007-01-16 01:53:29 -0800 | [diff] [blame] | 217 | flags= |
| 218 | test -n "$verbose" && flags="$flags -v" |
| 219 | test -n "$force" && flags="$flags -f" |
| 220 | GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 221 | git fetch--tool $flags native-store \ |
Junio C Hamano | fee7c2c | 2007-02-24 04:35:31 -0800 | [diff] [blame] | 222 | "$remote" "$remote_nick" "$refs" |
Junio C Hamano | b74e8cb | 2007-01-15 22:56:34 -0800 | [diff] [blame] | 223 | ) |
| 224 | ) || exit |
| 225 | |
| 226 | } |
| 227 | |
Paolo Bonzini | 9debc32 | 2007-03-15 09:23:20 +0100 | [diff] [blame] | 228 | fetch_per_ref () { |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 229 | reflist="$1" |
| 230 | refs= |
Santi Béjar | 4839bd8 | 2006-09-29 20:05:40 +0200 | [diff] [blame] | 231 | rref= |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 232 | |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 233 | for ref in $reflist |
| 234 | do |
| 235 | refs="$refs$LF$ref" |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 236 | |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 237 | # These are relative path from $GIT_DIR, typically starting at refs/ |
| 238 | # but may be HEAD |
Mark Wooding | f327dbc | 2006-04-13 22:01:24 +0000 | [diff] [blame] | 239 | if expr "z$ref" : 'z\.' >/dev/null |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 240 | then |
| 241 | not_for_merge=t |
Mark Wooding | f327dbc | 2006-04-13 22:01:24 +0000 | [diff] [blame] | 242 | ref=$(expr "z$ref" : 'z\.\(.*\)') |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 243 | else |
| 244 | not_for_merge= |
| 245 | fi |
Junio C Hamano | dfdcb55 | 2006-04-13 19:05:38 -0700 | [diff] [blame] | 246 | if expr "z$ref" : 'z+' >/dev/null |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 247 | then |
| 248 | single_force=t |
Junio C Hamano | dfdcb55 | 2006-04-13 19:05:38 -0700 | [diff] [blame] | 249 | ref=$(expr "z$ref" : 'z+\(.*\)') |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 250 | else |
| 251 | single_force= |
| 252 | fi |
Mark Wooding | f327dbc | 2006-04-13 22:01:24 +0000 | [diff] [blame] | 253 | remote_name=$(expr "z$ref" : 'z\([^:]*\):') |
| 254 | local_name=$(expr "z$ref" : 'z[^:]*:\(.*\)') |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 255 | |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 256 | rref="$rref$LF$remote_name" |
Junio C Hamano | 4447bad | 2005-09-17 11:56:41 -0700 | [diff] [blame] | 257 | |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 258 | # There are transports that can fetch only one head at a time... |
| 259 | case "$remote" in |
Sasha Khapyorsky | 38529e2 | 2006-09-14 05:24:04 +0300 | [diff] [blame] | 260 | http://* | https://* | ftp://*) |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 261 | test -n "$shallow_depth" && |
| 262 | die "shallow clone with http not supported" |
Tuncer Ayaz | ddaf731 | 2006-10-25 12:03:06 +0200 | [diff] [blame] | 263 | proto=`expr "$remote" : '\([^:]*\):'` |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 264 | if [ -n "$GIT_SSL_NO_VERIFY" ]; then |
| 265 | curl_extra_args="-k" |
| 266 | fi |
Sasha Khapyorsky | 3ea099d | 2006-09-29 03:10:44 +0300 | [diff] [blame] | 267 | if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 268 | "`git config --bool http.noEPSV`" = true ]; then |
Sasha Khapyorsky | 3ea099d | 2006-09-29 03:10:44 +0300 | [diff] [blame] | 269 | noepsv_opt="--disable-epsv" |
| 270 | fi |
Junio C Hamano | 2986c02 | 2006-11-22 22:24:09 -0800 | [diff] [blame] | 271 | |
| 272 | # Find $remote_name from ls-remote output. |
OGAWA Hirofumi | afb5f39 | 2007-04-24 04:26:26 +0900 | [diff] [blame] | 273 | head=$(echo "$ls_remote_result" | \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 274 | git fetch--tool -s pick-rref "$remote_name" "-") |
Mark Wooding | f327dbc | 2006-04-13 22:01:24 +0000 | [diff] [blame] | 275 | expr "z$head" : "z$_x40\$" >/dev/null || |
Junio C Hamano | 2986c02 | 2006-11-22 22:24:09 -0800 | [diff] [blame] | 276 | die "No such ref $remote_name at $remote" |
Tuncer Ayaz | ddaf731 | 2006-10-25 12:03:06 +0200 | [diff] [blame] | 277 | echo >&2 "Fetching $remote_name from $remote using $proto" |
Junio C Hamano | a858c00 | 2007-02-25 13:13:17 -0800 | [diff] [blame] | 278 | case "$quiet" in '') v=-v ;; *) v= ;; esac |
Junio C Hamano | 27be481 | 2007-04-08 23:27:22 -0700 | [diff] [blame] | 279 | git-http-fetch $v -a "$head" "$remote" || exit |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 280 | ;; |
| 281 | rsync://*) |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 282 | test -n "$shallow_depth" && |
| 283 | die "shallow clone with rsync not supported" |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 284 | TMP_HEAD="$GIT_DIR/TMP_HEAD" |
| 285 | rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1 |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 286 | head=$(git rev-parse --verify TMP_HEAD) |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 287 | rm -f "$TMP_HEAD" |
Junio C Hamano | a858c00 | 2007-02-25 13:13:17 -0800 | [diff] [blame] | 288 | case "$quiet" in '') v=-v ;; *) v= ;; esac |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 289 | test "$rsync_slurped_objects" || { |
Junio C Hamano | a858c00 | 2007-02-25 13:13:17 -0800 | [diff] [blame] | 290 | rsync -a $v --ignore-existing --exclude info \ |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 291 | "$remote/objects/" "$GIT_OBJECT_DIRECTORY/" || exit |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 292 | |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 293 | # 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 Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 314 | esac |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 315 | |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 316 | append_fetch_head "$head" "$remote" \ |
Junio C Hamano | f64d7fd | 2006-11-25 01:04:28 -0800 | [diff] [blame] | 317 | "$remote_name" "$remote_nick" "$local_name" "$not_for_merge" || exit |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 318 | |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 319 | done |
| 320 | |
Junio C Hamano | b74e8cb | 2007-01-15 22:56:34 -0800 | [diff] [blame] | 321 | } |
Junio C Hamano | ac9c110 | 2007-01-01 12:24:15 -0800 | [diff] [blame] | 322 | |
Junio C Hamano | b74e8cb | 2007-01-15 22:56:34 -0800 | [diff] [blame] | 323 | fetch_main () { |
| 324 | case "$remote" in |
| 325 | http://* | https://* | ftp://* | rsync://* ) |
Paolo Bonzini | 9debc32 | 2007-03-15 09:23:20 +0100 | [diff] [blame] | 326 | fetch_per_ref "$@" |
Junio C Hamano | b74e8cb | 2007-01-15 22:56:34 -0800 | [diff] [blame] | 327 | ;; |
| 328 | *) |
Paolo Bonzini | 9debc32 | 2007-03-15 09:23:20 +0100 | [diff] [blame] | 329 | fetch_all_at_once "$@" |
Junio C Hamano | b74e8cb | 2007-01-15 22:56:34 -0800 | [diff] [blame] | 330 | ;; |
| 331 | esac |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Junio C Hamano | f64d7fd | 2006-11-25 01:04:28 -0800 | [diff] [blame] | 334 | fetch_main "$reflist" || exit |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 335 | |
| 336 | # automated tag following |
| 337 | case "$no_tags$tags" in |
| 338 | '') |
Junio C Hamano | 6dc78e6 | 2006-02-22 13:10:37 -0800 | [diff] [blame] | 339 | case "$reflist" in |
| 340 | *:refs/*) |
| 341 | # effective only when we are following remote branch |
| 342 | # using local tracking branch. |
Junio C Hamano | ed9f7c9 | 2006-12-17 17:57:19 -0800 | [diff] [blame] | 343 | taglist=$(IFS=' ' && |
Junio C Hamano | 28b8e61 | 2006-11-22 21:57:14 -0800 | [diff] [blame] | 344 | echo "$ls_remote_result" | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 345 | git show-ref --exclude-existing=refs/tags/ | |
Junio C Hamano | 6dc78e6 | 2006-02-22 13:10:37 -0800 | [diff] [blame] | 346 | while read sha1 name |
| 347 | do |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 348 | git cat-file -t "$sha1" >/dev/null 2>&1 || continue |
Junio C Hamano | 6dc78e6 | 2006-02-22 13:10:37 -0800 | [diff] [blame] | 349 | echo >&2 "Auto-following $name" |
| 350 | echo ".${name}:${name}" |
| 351 | done) |
| 352 | esac |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 353 | case "$taglist" in |
| 354 | '') ;; |
| 355 | ?*) |
Alexandre Julliard | d158631 | 2006-11-24 15:59:12 +0100 | [diff] [blame] | 356 | # do not deepen a shallow tree when following tags |
| 357 | shallow_depth= |
Junio C Hamano | f64d7fd | 2006-11-25 01:04:28 -0800 | [diff] [blame] | 358 | fetch_main "$taglist" || exit ;; |
Junio C Hamano | 03febf9 | 2006-01-07 00:48:04 -0800 | [diff] [blame] | 359 | esac |
Junio C Hamano | 853a369 | 2005-08-20 02:54:34 -0700 | [diff] [blame] | 360 | esac |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 361 | |
| 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 Hamano | 9861718 | 2006-10-10 22:29:02 -0700 | [diff] [blame] | 364 | case "$orig_head" in |
| 365 | '') |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 366 | ;; |
Junio C Hamano | 9861718 | 2006-10-10 22:29:02 -0700 | [diff] [blame] | 367 | ?*) |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 368 | curr_head=$(git rev-parse --verify HEAD 2>/dev/null) |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 369 | if test "$curr_head" != "$orig_head" |
| 370 | then |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 371 | git update-ref \ |
Shawn O. Pearce | f947413 | 2006-12-28 02:34:48 -0500 | [diff] [blame] | 372 | -m "$GIT_REFLOG_ACTION: Undoing incorrectly fetched HEAD." \ |
Shawn Pearce | 55b7835 | 2006-07-10 23:38:35 -0400 | [diff] [blame] | 373 | HEAD "$orig_head" |
Junio C Hamano | b10ac50 | 2005-08-25 18:15:32 -0700 | [diff] [blame] | 374 | die "Cannot fetch into the current branch." |
| 375 | fi |
| 376 | ;; |
| 377 | esac |