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) || :;
7 if [ -d "$GIT_DIR"/remotes -a "$GIT_REWRITE_REMOTES" = true ]; then
8 echo "Rewriting $GIT_DIR/remotes" >&2
14 name=$(echo -n "$f" | tr -c "A-Za-z0-9" ".")
16 -e "s/^URL: /remote.$name.url . /p" \
17 -e "s/^Pull: /remote.$name.pull ^$ /p" \
18 -e "s/^Push: /remote.$name.push ^$ /p" \
22 } | while read key regex value; do
25 if [ $error = 0 ]; then
26 mv "$GIT_DIR"/remotes "$GIT_DIR"/remotes.old
29 git-repo-config $key "$value" $regex || error=1 ;;
37 # Not so fast. This could be the partial URL shorthand...
38 token=$(expr "z$1" : 'z\([^/]*\)/')
39 remainder=$(expr "z$1" : 'z[^/]*/\(.*\)')
40 if test "$(git-repo-config --get "remote.$token.url")"
43 elif test -f "$GIT_DIR/branches/$token"
51 if test "$(git-repo-config --get "remote.$1.url")"
54 elif test -f "$GIT_DIR/remotes/$1"
57 elif test -f "$GIT_DIR/branches/$1"
67 data_source=$(get_data_source "$1")
68 case "$data_source" in
72 token=$(expr "z$1" : '\([^/]*\)/')
73 remainder=$(expr "z$1" : '[^/]*/\(.*\)')
74 url=$(git-repo-config --get "remote.$token.url")
75 echo "$url/$remainder"
78 git-repo-config --get "remote.$1.url"
84 }' "$GIT_DIR/remotes/$1" ;;
86 sed -e 's/#.*//' "$GIT_DIR/branches/$1" ;;
88 token=$(expr "z$1" : 'z\([^/]*\)/')
89 remainder=$(expr "z$1" : 'z[^/]*/\(.*\)')
90 url=$(sed -e 's/#.*//' "$GIT_DIR/branches/$token")
91 echo "$url/$remainder"
94 die "internal error: get-remote-url $1" ;;
98 get_remote_default_refs_for_push () {
99 data_source=$(get_data_source "$1")
100 case "$data_source" in
101 '' | config-partial | branches | branches-partial)
102 ;; # no default push mapping, just send matching refs.
104 git-repo-config --get-all "remote.$1.push" ;;
108 }' "$GIT_DIR/remotes/$1" ;;
110 die "internal error: get-remote-default-ref-for-push $1" ;;
114 # Subroutine to canonicalize remote:local notation.
115 canon_refs_list_for_fetch () {
116 # Leave only the first one alone; add prefix . to the rest
117 # to prevent the secondary branches to be merged by default.
124 ref=$(expr "z$ref" : 'z+\(.*\)')
128 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
129 remote=$(expr "z$ref" : 'z\([^:]*\):')
130 local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
133 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
134 heads/* | tags/* | remotes/* ) remote="refs/$remote" ;;
135 *) remote="refs/heads/$remote" ;;
139 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
140 heads/* | tags/* | remotes/* ) local="refs/$local" ;;
141 *) local="refs/heads/$local" ;;
144 if local_ref_name=$(expr "z$local" : 'zrefs/\(.*\)')
146 git-check-ref-format "$local_ref_name" ||
147 die "* refusing to create funny ref '$local_ref_name' locally"
149 echo "${dot_prefix}${force}${remote}:${local}"
154 # Returns list of src: (no store), or src:dst (store)
155 get_remote_default_refs_for_fetch () {
156 data_source=$(get_data_source "$1")
157 case "$data_source" in
158 '' | config-partial | branches-partial)
161 canon_refs_list_for_fetch \
162 $(git-repo-config --get-all "remote.$1.pull") ;;
164 remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
165 case "$remote_branch" in '') remote_branch=master ;; esac
166 echo "refs/heads/${remote_branch}:refs/heads/$1"
169 # This prefixes the second and later default refspecs
170 # with a '.', to signal git-fetch to mark them
172 canon_refs_list_for_fetch $(sed -ne '/^Pull: */{
174 }' "$GIT_DIR/remotes/$1")
177 die "internal error: get-remote-default-ref-for-push $1" ;;
181 get_remote_refs_for_push () {
183 0) die "internal error: get-remote-refs-for-push." ;;
184 1) get_remote_default_refs_for_push "$@" ;;
185 *) shift; echo "$@" ;;
189 get_remote_refs_for_fetch () {
192 die "internal error: get-remote-refs-for-fetch." ;;
194 get_remote_default_refs_for_fetch "$@" ;;
200 if test "$tag_just_seen"
202 echo "refs/tags/${ref}:refs/tags/${ref}"
213 canon_refs_list_for_fetch "$ref"
219 resolve_alternates () {
220 # original URL (xxx.git)
221 top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
228 echo "$top_$path/" ;;
230 # relative -- ugly but seems to work.
231 echo "$1/objects/$path/" ;;
233 # exit code may not be caught by the reader.
234 echo "bad alternate: $path"