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
) ||
:;
16 if test "$(git-config --get "remote.
$1.url
")"
19 elif test -f "$GIT_DIR/remotes/$1"
22 elif test -f "$GIT_DIR/branches/$1"
32 data_source
=$
(get_data_source
"$1")
33 case "$data_source" in
41 git-config
--get "remote.$1.url"
47 }' "$GIT_DIR/remotes/$1"
50 sed -e 's/#.*//' "$GIT_DIR/branches/$1"
53 die
"internal error: get-remote-url $1" ;;
57 get_default_remote
() {
58 curr_branch
=$
(git-symbolic-ref
-q HEAD |
sed -e 's|^refs/heads/||')
59 origin
=$
(git-config
--get "branch.$curr_branch.remote")
60 echo ${origin:-origin}
63 get_remote_default_refs_for_push
() {
64 data_source
=$
(get_data_source
"$1")
65 case "$data_source" in
67 ;; # no default push mapping, just send matching refs.
69 git-config
--get-all "remote.$1.push" ;;
73 }' "$GIT_DIR/remotes/$1" ;;
75 die
"internal error: get-remote-default-ref-for-push $1" ;;
79 # Called from canon_refs_list_for_fetch -d "$remote", which
80 # is called from get_remote_default_refs_for_fetch to grok
81 # refspecs that are retrieved from the configuration, but not
82 # from get_remote_refs_for_fetch when it deals with refspecs
83 # supplied on the command line. $ls_remote_result has the list
84 # of refs available at remote.
86 # The first token returned is either "explicit" or "glob"; this
87 # is to help prevent randomly "globbed" ref from being chosen as
89 expand_refs_wildcard
() {
90 echo "$ls_remote_result" |
91 git fetch--tool expand-refs-wildcard
"-" "$@"
94 # Subroutine to canonicalize remote:local notation.
95 canon_refs_list_for_fetch
() {
96 # If called from get_remote_default_refs_for_fetch
97 # leave the branches in branch.${curr_branch}.merge alone,
98 # or the first one otherwise; add prefix . to the rest
99 # to prevent the secondary branches to be merged by default.
104 shift ; remote
="$1" ; shift
105 set $
(expand_refs_wildcard
"$remote" "$@")
108 if test "$remote" = "$(get_default_remote)"
110 curr_branch
=$
(git-symbolic-ref
-q HEAD | \
111 sed -e 's|^refs/heads/||')
112 merge_branches
=$
(git-config \
113 --get-all "branch.${curr_branch}.merge")
115 if test -z "$merge_branches" && test $is_explicit != explicit
117 merge_branches
=..this.will.never.match.any.ref..
125 ref
=$
(expr "z$ref" : 'z+\(.*\)')
129 expr "z$ref" : 'z.*:' >/dev
/null || ref
="${ref}:"
130 remote
=$
(expr "z$ref" : 'z\([^:]*\):')
131 local=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
133 if test -z "$merge_branches"
135 merge_branches
=$remote
138 for merge_branch
in $merge_branches
140 [ "$remote" = "$merge_branch" ] &&
145 '' | HEAD
) remote
=HEAD
;;
147 heads
/* | tags
/* | remotes
/* ) remote
="refs/$remote" ;;
148 *) remote
="refs/heads/$remote" ;;
153 heads
/* | tags
/* | remotes
/* ) local="refs/$local" ;;
154 *) local="refs/heads/$local" ;;
157 if local_ref_name
=$
(expr "z$local" : 'zrefs/\(.*\)')
159 git-check-ref-format
"$local_ref_name" ||
160 die
"* refusing to create funny ref '$local_ref_name' locally"
162 echo "${dot_prefix}${force}${remote}:${local}"
166 # Returns list of src: (no store), or src:dst (store)
167 get_remote_default_refs_for_fetch
() {
168 data_source
=$
(get_data_source
"$1")
169 case "$data_source" in
173 canon_refs_list_for_fetch
-d "$1" \
174 $
(git-for-each-ref
--format='%(refname):')
177 canon_refs_list_for_fetch
-d "$1" \
178 $
(git-config
--get-all "remote.$1.fetch") ;;
180 remote_branch
=$
(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
181 case "$remote_branch" in '') remote_branch
=master
;; esac
182 echo "refs/heads/${remote_branch}:refs/heads/$1"
185 canon_refs_list_for_fetch
-d "$1" $
(sed -ne '/^Pull: */{
187 }' "$GIT_DIR/remotes/$1")
190 die
"internal error: get-remote-default-ref-for-fetch $1" ;;
194 get_remote_refs_for_push
() {
196 0) die
"internal error: get-remote-refs-for-push." ;;
197 1) get_remote_default_refs_for_push
"$@" ;;
198 *) shift; echo "$@" ;;
202 get_remote_refs_for_fetch
() {
205 die
"internal error: get-remote-refs-for-fetch." ;;
207 get_remote_default_refs_for_fetch
"$@" ;;
213 if test "$tag_just_seen"
215 echo "refs/tags/${ref}:refs/tags/${ref}"
226 canon_refs_list_for_fetch
"$ref"
232 resolve_alternates
() {
233 # original URL (xxx.git)
234 top_
=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
241 echo "$top_$path/" ;;
243 # relative -- ugly but seems to work.
244 echo "$1/objects/$path/" ;;
246 # exit code may not be caught by the reader.
247 echo "bad alternate: $path"
254 data_source
=$
(get_data_source
"$1")
255 case "$data_source" in
257 uplp
=$
(git-config
--get "remote.$1.uploadpack")
258 echo ${uplp:-git-upload-pack}
261 echo "git-upload-pack"