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) || :;
10 # Not so fast. This could be the partial URL shorthand...
11 token=$(expr "z$1" : 'z\([^/]*\)/')
12 remainder=$(expr "z$1" : 'z[^/]*/\(.*\)')
13 if test "$(git-repo-config --get "remote.$token.url")"
16 elif test -f "$GIT_DIR/branches/$token"
24 if test "$(git-repo-config --get "remote.$1.url")"
27 elif test -f "$GIT_DIR/remotes/$1"
30 elif test -f "$GIT_DIR/branches/$1"
40 data_source=$(get_data_source "$1")
41 case "$data_source" in
45 token=$(expr "z$1" : 'z\([^/]*\)/')
46 remainder=$(expr "z$1" : 'z[^/]*/\(.*\)')
47 url=$(git-repo-config --get "remote.$token.url")
48 echo "$url/$remainder"
51 git-repo-config --get "remote.$1.url"
57 }' "$GIT_DIR/remotes/$1" ;;
59 sed -e 's/#.*//' "$GIT_DIR/branches/$1" ;;
61 token=$(expr "z$1" : 'z\([^/]*\)/')
62 remainder=$(expr "z$1" : 'z[^/]*/\(.*\)')
63 url=$(sed -e 's/#.*//' "$GIT_DIR/branches/$token")
64 echo "$url/$remainder"
67 die "internal error: get-remote-url $1" ;;
71 get_default_remote () {
72 curr_branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
73 origin=$(git-repo-config --get "branch.$curr_branch.remote")
74 echo ${origin:-origin}
77 get_remote_default_refs_for_push () {
78 data_source=$(get_data_source "$1")
79 case "$data_source" in
80 '' | config-partial | branches | branches-partial)
81 ;; # no default push mapping, just send matching refs.
83 git-repo-config --get-all "remote.$1.push" ;;
87 }' "$GIT_DIR/remotes/$1" ;;
89 die "internal error: get-remote-default-ref-for-push $1" ;;
93 # Subroutine to canonicalize remote:local notation.
94 canon_refs_list_for_fetch () {
95 # If called from get_remote_default_refs_for_fetch
96 # leave the branches in branch.${curr_branch}.merge alone,
97 # or the first one otherwise; add prefix . to the rest
98 # to prevent the secondary branches to be merged by default.
102 shift ; remote="$1" ; shift
103 if test "$remote" = "$(get_default_remote)"
105 curr_branch=$(git-symbolic-ref HEAD | \
106 sed -e 's|^refs/heads/||')
107 merge_branches=$(git-repo-config \
108 --get-all "branch.${curr_branch}.merge")
116 ref=$(expr "z$ref" : 'z+\(.*\)')
120 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
121 remote=$(expr "z$ref" : 'z\([^:]*\):')
122 local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
124 if test -z "$merge_branches"
126 merge_branches=$remote
129 for merge_branch in $merge_branches
131 [ "$remote" = "$merge_branch" ] &&
137 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
138 heads/* | tags/* | remotes/* ) remote="refs/$remote" ;;
139 *) remote="refs/heads/$remote" ;;
143 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
144 heads/* | tags/* | remotes/* ) local="refs/$local" ;;
145 *) local="refs/heads/$local" ;;
148 if local_ref_name=$(expr "z$local" : 'zrefs/\(.*\)')
150 git-check-ref-format "$local_ref_name" ||
151 die "* refusing to create funny ref '$local_ref_name' locally"
153 echo "${dot_prefix}${force}${remote}:${local}"
157 # Returns list of src: (no store), or src:dst (store)
158 get_remote_default_refs_for_fetch () {
159 data_source=$(get_data_source "$1")
160 case "$data_source" in
161 '' | config-partial | branches-partial)
164 canon_refs_list_for_fetch -d "$1" \
165 $(git-repo-config --get-all "remote.$1.fetch") ;;
167 remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
168 case "$remote_branch" in '') remote_branch=master ;; esac
169 echo "refs/heads/${remote_branch}:refs/heads/$1"
172 canon_refs_list_for_fetch -d "$1" $(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"