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 git fetch--tool expand-refs-wildcard "$ls_remote_result" "$@"
87 # Subroutine to canonicalize remote:local notation.
88 canon_refs_list_for_fetch () {
89 # If called from get_remote_default_refs_for_fetch
90 # leave the branches in branch.${curr_branch}.merge alone,
91 # or the first one otherwise; add prefix . to the rest
92 # to prevent the secondary branches to be merged by default.
97 shift ; remote="$1" ; shift
98 set $(expand_refs_wildcard "$remote" "$@")
101 if test "$remote" = "$(get_default_remote)"
103 curr_branch=$(git-symbolic-ref -q HEAD | \
104 sed -e 's|^refs/heads/||')
105 merge_branches=$(git-config \
106 --get-all "branch.${curr_branch}.merge")
108 if test -z "$merge_branches" && test $is_explicit != explicit
110 merge_branches=..this.will.never.match.any.ref..
118 ref=$(expr "z$ref" : 'z+\(.*\)')
122 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
123 remote=$(expr "z$ref" : 'z\([^:]*\):')
124 local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
126 if test -z "$merge_branches"
128 merge_branches=$remote
131 for merge_branch in $merge_branches
133 [ "$remote" = "$merge_branch" ] &&
138 '' | HEAD ) remote=HEAD ;;
139 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
140 heads/* | tags/* | remotes/* ) remote="refs/$remote" ;;
141 *) remote="refs/heads/$remote" ;;
145 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
146 heads/* | tags/* | remotes/* ) local="refs/$local" ;;
147 *) local="refs/heads/$local" ;;
150 if local_ref_name=$(expr "z$local" : 'zrefs/\(.*\)')
152 git-check-ref-format "$local_ref_name" ||
153 die "* refusing to create funny ref '$local_ref_name' locally"
155 echo "${dot_prefix}${force}${remote}:${local}"
159 # Returns list of src: (no store), or src:dst (store)
160 get_remote_default_refs_for_fetch () {
161 data_source=$(get_data_source "$1")
162 case "$data_source" in
166 canon_refs_list_for_fetch -d "$1" \
167 $(git-config --get-all "remote.$1.fetch") ;;
169 remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
170 case "$remote_branch" in '') remote_branch=master ;; esac
171 echo "refs/heads/${remote_branch}:refs/heads/$1"
174 canon_refs_list_for_fetch -d "$1" $(sed -ne '/^Pull: */{
176 }' "$GIT_DIR/remotes/$1")
179 die "internal error: get-remote-default-ref-for-push $1" ;;
183 get_remote_refs_for_push () {
185 0) die "internal error: get-remote-refs-for-push." ;;
186 1) get_remote_default_refs_for_push "$@" ;;
187 *) shift; echo "$@" ;;
191 get_remote_refs_for_fetch () {
194 die "internal error: get-remote-refs-for-fetch." ;;
196 get_remote_default_refs_for_fetch "$@" ;;
202 if test "$tag_just_seen"
204 echo "refs/tags/${ref}:refs/tags/${ref}"
215 canon_refs_list_for_fetch "$ref"
221 resolve_alternates () {
222 # original URL (xxx.git)
223 top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
230 echo "$top_$path/" ;;
232 # relative -- ugly but seems to work.
233 echo "$1/objects/$path/" ;;
235 # exit code may not be caught by the reader.
236 echo "bad alternate: $path"
243 data_source=$(get_data_source "$1")
244 case "$data_source" in
246 uplp=$(git-config --get "remote.$1.uploadpack")
247 echo ${uplp:-git-upload-pack}
250 echo "git-upload-pack"