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 () {
84 echo "$ls_remote_result" |
85 git fetch--tool expand-refs-wildcard "-" "$@"
88 # Subroutine to canonicalize remote:local notation.
89 canon_refs_list_for_fetch () {
90 # If called from get_remote_default_refs_for_fetch
91 # leave the branches in branch.${curr_branch}.merge alone,
92 # or the first one otherwise; add prefix . to the rest
93 # to prevent the secondary branches to be merged by default.
98 shift ; remote="$1" ; shift
99 set $(expand_refs_wildcard "$remote" "$@")
102 if test "$remote" = "$(get_default_remote)"
104 curr_branch=$(git-symbolic-ref -q HEAD | \
105 sed -e 's|^refs/heads/||')
106 merge_branches=$(git-config \
107 --get-all "branch.${curr_branch}.merge")
109 if test -z "$merge_branches" && test $is_explicit != explicit
111 merge_branches=..this.will.never.match.any.ref..
119 ref=$(expr "z$ref" : 'z+\(.*\)')
123 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
124 remote=$(expr "z$ref" : 'z\([^:]*\):')
125 local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
127 if test -z "$merge_branches"
129 merge_branches=$remote
132 for merge_branch in $merge_branches
134 [ "$remote" = "$merge_branch" ] &&
139 '' | HEAD ) remote=HEAD ;;
140 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
141 heads/* | tags/* | remotes/* ) remote="refs/$remote" ;;
142 *) remote="refs/heads/$remote" ;;
146 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
147 heads/* | tags/* | remotes/* ) local="refs/$local" ;;
148 *) local="refs/heads/$local" ;;
151 if local_ref_name=$(expr "z$local" : 'zrefs/\(.*\)')
153 git-check-ref-format "$local_ref_name" ||
154 die "* refusing to create funny ref '$local_ref_name' locally"
156 echo "${dot_prefix}${force}${remote}:${local}"
160 # Returns list of src: (no store), or src:dst (store)
161 get_remote_default_refs_for_fetch () {
162 data_source=$(get_data_source "$1")
163 case "$data_source" in
167 canon_refs_list_for_fetch -d "$1" \
168 $(git-config --get-all "remote.$1.fetch") ;;
170 remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
171 case "$remote_branch" in '') remote_branch=master ;; esac
172 echo "refs/heads/${remote_branch}:refs/heads/$1"
175 canon_refs_list_for_fetch -d "$1" $(sed -ne '/^Pull: */{
177 }' "$GIT_DIR/remotes/$1")
180 die "internal error: get-remote-default-ref-for-push $1" ;;
184 get_remote_refs_for_push () {
186 0) die "internal error: get-remote-refs-for-push." ;;
187 1) get_remote_default_refs_for_push "$@" ;;
188 *) shift; echo "$@" ;;
192 get_remote_refs_for_fetch () {
195 die "internal error: get-remote-refs-for-fetch." ;;
197 get_remote_default_refs_for_fetch "$@" ;;
203 if test "$tag_just_seen"
205 echo "refs/tags/${ref}:refs/tags/${ref}"
216 canon_refs_list_for_fetch "$ref"
222 resolve_alternates () {
223 # original URL (xxx.git)
224 top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
231 echo "$top_$path/" ;;
233 # relative -- ugly but seems to work.
234 echo "$1/objects/$path/" ;;
236 # exit code may not be caught by the reader.
237 echo "bad alternate: $path"
244 data_source=$(get_data_source "$1")
245 case "$data_source" in
247 uplp=$(git-config --get "remote.$1.uploadpack")
248 echo ${uplp:-git-upload-pack}
251 echo "git-upload-pack"