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 "$1" : '\([^/]*\)/')
12 remainder=$(expr "$1" : '[^/]*/\(.*\)')
13 if test -f "$GIT_DIR/branches/$token"
21 if test -f "$GIT_DIR/remotes/$1"
24 elif test -f "$GIT_DIR/branches/$1"
34 data_source=$(get_data_source "$1")
35 case "$data_source" in
42 }' "$GIT_DIR/remotes/$1" ;;
44 sed -e 's/#.*//' "$GIT_DIR/branches/$1" ;;
46 token=$(expr "$1" : '\([^/]*\)/')
47 remainder=$(expr "$1" : '[^/]*/\(.*\)')
48 url=$(sed -e 's/#.*//' "$GIT_DIR/branches/$token")
49 echo "$url/$remainder"
52 die "internal error: get-remote-url $1" ;;
56 get_remote_default_refs_for_push () {
57 data_source=$(get_data_source "$1")
58 case "$data_source" in
59 '' | branches | branches-partial)
60 ;; # no default push mapping, just send matching refs.
64 }' "$GIT_DIR/remotes/$1" ;;
66 die "internal error: get-remote-default-ref-for-push $1" ;;
70 # Subroutine to canonicalize remote:local notation.
71 canon_refs_list_for_fetch () {
72 # Leave only the first one alone; add prefix . to the rest
73 # to prevent the secondary branches to be merged by default.
80 ref=$(expr "$ref" : '\+\(.*\)')
84 expr "$ref" : '.*:' >/dev/null || ref="${ref}:"
85 remote=$(expr "$ref" : '\([^:]*\):')
86 local=$(expr "$ref" : '[^:]*:\(.*\)')
89 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
90 heads/* | tags/* | remotes/* ) remote="refs/$remote" ;;
91 *) remote="refs/heads/$remote" ;;
95 refs/heads/* | refs/tags/* | refs/remotes/*) ;;
96 heads/* | tags/* | remotes/* ) local="refs/$local" ;;
97 *) local="refs/heads/$local" ;;
100 if local_ref_name=$(expr "$local" : 'refs/\(.*\)')
102 git-check-ref-format "$local_ref_name" ||
103 die "* refusing to create funny ref '$local_ref_name' locally"
105 echo "${dot_prefix}${force}${remote}:${local}"
110 # Returns list of src: (no store), or src:dst (store)
111 get_remote_default_refs_for_fetch () {
112 data_source=$(get_data_source "$1")
113 case "$data_source" in
114 '' | branches-partial)
117 remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
118 case "$remote_branch" in '') remote_branch=master ;; esac
119 echo "refs/heads/${remote_branch}:refs/heads/$1"
122 # This prefixes the second and later default refspecs
123 # with a '.', to signal git-fetch to mark them
125 canon_refs_list_for_fetch $(sed -ne '/^Pull: */{
127 }' "$GIT_DIR/remotes/$1")
130 die "internal error: get-remote-default-ref-for-push $1" ;;
134 get_remote_refs_for_push () {
136 0) die "internal error: get-remote-refs-for-push." ;;
137 1) get_remote_default_refs_for_push "$@" ;;
138 *) shift; echo "$@" ;;
142 get_remote_refs_for_fetch () {
145 die "internal error: get-remote-refs-for-fetch." ;;
147 get_remote_default_refs_for_fetch "$@" ;;
153 if test "$tag_just_seen"
155 echo "refs/tags/${ref}:refs/tags/${ref}"
166 canon_refs_list_for_fetch "$ref"
172 resolve_alternates () {
173 # original URL (xxx.git)
174 top_=`expr "$1" : '\([^:]*:/*[^/]*\)/'`
181 echo "$top_$path/" ;;
183 # relative -- ugly but seems to work.
184 echo "$1/objects/$path/" ;;
186 # exit code may not be caught by the reader.
187 echo "bad alternate: $path"