3 # git-ls-remote could be called from outside a git managed repository;
4 # this would fail in that case and would issue an error message.
5 GIT_DIR
=$
(git-rev-parse
--git-dir 2>/dev
/null
) ||
:;
13 if test "$(git-config --get "remote.
$1.url
")"
16 elif test -f "$GIT_DIR/remotes/$1"
19 elif test -f "$GIT_DIR/branches/$1"
29 data_source
=$
(get_data_source
"$1")
30 case "$data_source" in
35 git-config
--get "remote.$1.url"
41 }' "$GIT_DIR/remotes/$1"
44 sed -e 's/#.*//' "$GIT_DIR/branches/$1"
47 die
"internal error: get-remote-url $1" ;;
51 get_default_remote
() {
52 curr_branch
=$
(git-symbolic-ref
-q HEAD |
sed -e 's|^refs/heads/||')
53 origin
=$
(git-config
--get "branch.$curr_branch.remote")
54 echo ${origin:-origin}
57 get_remote_default_refs_for_push
() {
58 data_source
=$
(get_data_source
"$1")
59 case "$data_source" in
61 ;; # no default push mapping, just send matching refs.
63 git-config
--get-all "remote.$1.push" ;;
67 }' "$GIT_DIR/remotes/$1" ;;
69 die
"internal error: get-remote-default-ref-for-push $1" ;;
73 # Called from canon_refs_list_for_fetch -d "$remote", which
74 # is called from get_remote_default_refs_for_fetch to grok
75 # refspecs that are retrieved from the configuration, but not
76 # from get_remote_refs_for_fetch when it deals with refspecs
77 # supplied on the command line. $ls_remote_result has the list
78 # of refs available at remote.
80 # The first token returned is either "explicit" or "glob"; this
81 # is to help prevent randomly "globbed" ref from being chosen as
83 expand_refs_wildcard
() {
90 echo >&2 "Nothing specified for fetching with remote.$remote.fetch"
95 # a non glob pattern is given back as-is.
96 expr "z$lref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev
/null ||
{
97 if test -n "$first_one"
107 if test -n "$first_one"
112 from
=`expr "z$lref" : 'z\(refs/.*/\)\*:refs/.*/\*$'`
113 to
=`expr "z$lref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'`
115 test "z$lref" = "z$ref" || local_force
='+'
116 echo "$ls_remote_result" |
122 # ignore the ones that do not start with $from
123 mapped
=${name#"$from"}
124 test "z$name" = "z$mapped" && continue
125 echo "${local_force}${name}:${to}${mapped}"
131 # Subroutine to canonicalize remote:local notation.
132 canon_refs_list_for_fetch
() {
133 # If called from get_remote_default_refs_for_fetch
134 # leave the branches in branch.${curr_branch}.merge alone,
135 # or the first one otherwise; add prefix . to the rest
136 # to prevent the secondary branches to be merged by default.
141 shift ; remote
="$1" ; shift
142 set $
(expand_refs_wildcard
"$remote" "$@")
145 if test "$remote" = "$(get_default_remote)"
147 curr_branch
=$
(git-symbolic-ref
-q HEAD | \
148 sed -e 's|^refs/heads/||')
149 merge_branches
=$
(git-config \
150 --get-all "branch.${curr_branch}.merge")
152 if test -z "$merge_branches" && test $is_explicit != explicit
154 merge_branches
=..this.will.never.match.any.ref..
162 ref
=$
(expr "z$ref" : 'z+\(.*\)')
166 expr "z$ref" : 'z.*:' >/dev
/null || ref
="${ref}:"
167 remote
=$
(expr "z$ref" : 'z\([^:]*\):')
168 local=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
170 if test -z "$merge_branches"
172 merge_branches
=$remote
175 for merge_branch
in $merge_branches
177 if test "$remote" = "$merge_branch" ||
178 test "$local" = "$merge_branch"
186 '' | HEAD
) remote
=HEAD
;;
187 refs
/heads
/* | refs
/tags
/* | refs
/remotes
/*) ;;
188 heads
/* | tags
/* | remotes
/* ) remote
="refs/$remote" ;;
189 *) remote
="refs/heads/$remote" ;;
193 refs
/heads
/* | refs
/tags
/* | refs
/remotes
/*) ;;
194 heads
/* | tags
/* | remotes
/* ) local="refs/$local" ;;
195 *) local="refs/heads/$local" ;;
198 if local_ref_name
=$
(expr "z$local" : 'zrefs/\(.*\)')
200 git-check-ref-format
"$local_ref_name" ||
201 die
"* refusing to create funny ref '$local_ref_name' locally"
203 echo "${dot_prefix}${force}${remote}:${local}"
207 # Returns list of src: (no store), or src:dst (store)
208 get_remote_default_refs_for_fetch
() {
209 data_source
=$
(get_data_source
"$1")
210 case "$data_source" in
214 canon_refs_list_for_fetch
-d "$1" \
215 $
(git-config
--get-all "remote.$1.fetch") ;;
217 remote_branch
=$
(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
218 case "$remote_branch" in '') remote_branch
=master
;; esac
219 echo "refs/heads/${remote_branch}:refs/heads/$1"
222 canon_refs_list_for_fetch
-d "$1" $
(sed -ne '/^Pull: */{
224 }' "$GIT_DIR/remotes/$1")
227 die
"internal error: get-remote-default-ref-for-push $1" ;;
231 get_remote_refs_for_push
() {
233 0) die
"internal error: get-remote-refs-for-push." ;;
234 1) get_remote_default_refs_for_push
"$@" ;;
235 *) shift; echo "$@" ;;
239 get_remote_refs_for_fetch
() {
242 die
"internal error: get-remote-refs-for-fetch." ;;
244 get_remote_default_refs_for_fetch
"$@" ;;
250 if test "$tag_just_seen"
252 echo "refs/tags/${ref}:refs/tags/${ref}"
263 canon_refs_list_for_fetch
"$ref"
269 resolve_alternates
() {
270 # original URL (xxx.git)
271 top_
=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
278 echo "$top_$path/" ;;
280 # relative -- ugly but seems to work.
281 echo "$1/objects/$path/" ;;
283 # exit code may not be caught by the reader.
284 echo "bad alternate: $path"
291 data_source
=$
(get_data_source
"$1")
292 case "$data_source" in
294 uplp
=$
(git-config
--get "remote.$1.uploadpack")
295 echo ${uplp:-git-upload-pack}
298 echo "git-upload-pack"