]> git.ipfire.org Git - thirdparty/git.git/blame - git-fetch-script
[PATCH] Use git-octopus when pulling more than one heads.
[thirdparty/git.git] / git-fetch-script
CommitLineData
7ef76925
LT
1#!/bin/sh
2#
b33e9666 3. git-sh-setup-script || die "Not a git archive"
853a3697
JH
4. git-parse-remote-script
5_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
6_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
7
8append=
ae2da406
JH
9force=
10while case "$#" in 0) break ;; esac
11do
12 case "$1" in
13 -a|--a|--ap|--app|--appe|--appen|--append)
14 append=t
15 shift
16 ;;
17 -f|--f|--fo|--for|--forc|--force)
18 force=t
19 shift
20 ;;
21 *)
22 break
23 ;;
24 esac
25done
26
853a3697
JH
27case "$#" in
280)
92c533ef
JH
29 test -f "$GIT_DIR/branches/origin" ||
30 test -f "$GIT_DIR/remotes/origin" ||
31 die "Where do you want to fetch from?"
32 set origin ;;
853a3697 33esac
ae2da406 34
853a3697
JH
35remote_nick="$1"
36remote=$(get_remote_url "$@")
37refs=
38rref=
39rsync_slurped_objects=
40
41if test "" = "$append"
42then
43 : >$GIT_DIR/FETCH_HEAD
44fi
45
46append_fetch_head () {
47 head_="$1"
48 remote_="$2"
49 remote_name_="$3"
50 remote_nick_="$4"
51 local_name_="$5"
52
53 # 2.6.11-tree tag would not be happy to be fed to resolve.
54 if git-cat-file commit "$head_" >/dev/null 2>&1
55 then
56 head_=$(git-rev-parse --verify "$head_^0") || exit
57 note_="$head_ $remote_name_ from $remote_nick_"
58 echo "$note_" >>$GIT_DIR/FETCH_HEAD
59 echo >&2 "* committish: $note_"
60 else
61 echo >&2 "* non-commit: $note_"
62 fi
63 if test "$local_name_" != ""
64 then
65 # We are storing the head locally. Make sure that it is
66 # a fast forward (aka "reverse push").
67 fast_forward_local "$local_name_" "$head_" "$remote_" "$remote_name_"
68 fi
69}
70
71fast_forward_local () {
72 case "$1" in
73 refs/tags/*)
74 # Tags need not be pointing at commits so there
75 # is no way to guarantee "fast-forward" anyway.
ae2da406
JH
76 if test -f "$GIT_DIR/$1"
77 then
78 echo >&2 "* $1: updating with $4"
79 echo >&2 " from $3."
80 else
81 echo >&2 "* $1: storing $4"
82 echo >&2 " from $3."
83 fi
853a3697 84 echo "$2" >"$GIT_DIR/$1" ;;
ae2da406 85
853a3697
JH
86 refs/heads/*)
87 # NEEDSWORK: use the same cmpxchg protocol here.
88 echo "$2" >"$GIT_DIR/$1.lock"
89 if test -f "$GIT_DIR/$1"
33b83034 90 then
853a3697
JH
91 local=$(git-rev-parse --verify "$1^0") &&
92 mb=$(git-merge-base "$local" "$2") &&
93 case "$2,$mb" in
94 $local,*)
95 echo >&2 "* $1: same as $4"
96 echo >&2 " from $3"
97 ;;
98 *,$local)
99 echo >&2 "* $1: fast forward to $4"
100 echo >&2 " from $3"
101 ;;
102 *)
103 false
104 ;;
105 esac || {
853a3697 106 echo >&2 "* $1: does not fast forward to $4"
ae2da406
JH
107 case "$force" in
108 t)
109 echo >&2 " from $3; forcing update."
110 ;;
111 *)
112 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1.remote"
113 echo >&2 " from $3; leaving it in '$1.remote'"
114 ;;
115 esac
853a3697
JH
116 }
117 else
118 echo >&2 "* $1: storing $4"
119 echo >&2 " from $3."
33b83034 120 fi
853a3697
JH
121 test -f "$GIT_DIR/$1.lock" &&
122 mv "$GIT_DIR/$1.lock" "$GIT_DIR/$1"
0a623e7c 123 ;;
853a3697
JH
124 esac
125}
126
127for ref in $(get_remote_refs_for_fetch "$@")
128do
129 refs="$refs $ref"
f170e4b3 130
853a3697
JH
131 # These are relative path from $GIT_DIR, typically starting at refs/
132 # but may be HEAD
133 remote_name=$(expr "$ref" : '\([^:]*\):')
134 local_name=$(expr "$ref" : '[^:]*:\(.*\)')
f170e4b3 135
853a3697
JH
136 rref="$rref $remote_name"
137
138 # There are transports that can fetch only one head at a time...
139 case "$remote" in
140 http://* | https://*)
141 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
142 curl_extra_args="-k"
143 fi
144 head=$(curl -nsf $curl_extra_args "$remote/$remote_name") &&
145 expr "$head" : "$_x40\$" >/dev/null ||
146 die "Failed to fetch $remote_name from $remote"
147 echo Fetching "$remote_name from $remote" using http
148 git-http-pull -v -a "$head" "$remote/" || exit
60ea0fdd 149 ;;
853a3697
JH
150 rsync://*)
151 TMP_HEAD="$GIT_DIR/TMP_HEAD"
152 rsync -L "$remote/$remote_name" "$TMP_HEAD" || exit 1
153 head=$(git-rev-parse TMP_HEAD)
154 rm -f "$TMP_HEAD"
155 test "$rsync_slurped_objects" || {
156 rsync -avz --ignore-existing "$remote/objects/" \
157 "$GIT_OBJECT_DIRECTORY/" || exit
158 rsync_slurped_objects=t
159 }
160 ;;
161 *)
162 # We will do git native transport with just one call later.
163 continue ;;
164 esac
165
166 append_fetch_head "$head" "$remote" "$remote_name" "$remote_nick" "$local_name"
f170e4b3 167
853a3697
JH
168done
169
170case "$remote" in
171http://* | https://* | rsync://* )
172 ;; # we are already done.
173*)
174 git-fetch-pack "$remote" $rref |
175 while read sha1 remote_name
176 do
177 found=
178 for ref in $refs
179 do
180 case "$ref" in
181 $remote_name:*)
182 found="$ref"
183 break ;;
184 esac
185 done
f170e4b3 186
853a3697
JH
187 local_name=$(expr "$found" : '[^:]*:\(.*\)')
188 append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"
189 done
190 ;;
191esac