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" ;;
54 esac |
sed "s|^\(.[^:][^:]*\):\(/[^/]\)|ssh://\1\2|"
55 # work around MinGW path mangling
58 get_default_remote
() {
59 curr_branch
=$
(git symbolic-ref
-q HEAD |
sed -e 's|^refs/heads/||')
60 origin
=$
(git config
--get "branch.$curr_branch.remote")
61 echo ${origin:-origin}
64 get_remote_default_refs_for_push
() {
65 data_source
=$
(get_data_source
"$1")
66 case "$data_source" in
68 ;; # no default push mapping, just send matching refs.
70 git config
--get-all "remote.$1.push" ;;
74 }' "$GIT_DIR/remotes/$1" ;;
76 die
"internal error: get-remote-default-ref-for-push $1" ;;
80 # Called from canon_refs_list_for_fetch -d "$remote", which
81 # is called from get_remote_default_refs_for_fetch to grok
82 # refspecs that are retrieved from the configuration, but not
83 # from get_remote_refs_for_fetch when it deals with refspecs
84 # supplied on the command line. $ls_remote_result has the list
85 # of refs available at remote.
87 # The first token returned is either "explicit" or "glob"; this
88 # is to help prevent randomly "globbed" ref from being chosen as
90 expand_refs_wildcard
() {
91 echo "$ls_remote_result" |
92 git fetch--tool expand-refs-wildcard
"-" "$@"
95 # Subroutine to canonicalize remote:local notation.
96 canon_refs_list_for_fetch
() {
97 # If called from get_remote_default_refs_for_fetch
98 # leave the branches in branch.${curr_branch}.merge alone,
99 # or the first one otherwise; add prefix . to the rest
100 # to prevent the secondary branches to be merged by default.
105 shift ; remote
="$1" ; shift
106 set $
(expand_refs_wildcard
"$remote" "$@")
109 if test "$remote" = "$(get_default_remote)"
111 curr_branch
=$
(git symbolic-ref
-q HEAD | \
112 sed -e 's|^refs/heads/||')
113 merge_branches
=$
(git config \
114 --get-all "branch.${curr_branch}.merge")
116 if test -z "$merge_branches" && test $is_explicit != explicit
118 merge_branches
=..this.will.never.match.any.ref..
126 ref
=$
(expr "z$ref" : 'z+\(.*\)')
130 expr "z$ref" : 'z.*:' >/dev
/null || ref
="${ref}:"
131 remote
=$
(expr "z$ref" : 'z\([^:]*\):')
132 local=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
134 if test -z "$merge_branches"
136 merge_branches
=$remote
139 for merge_branch
in $merge_branches
141 [ "$remote" = "$merge_branch" ] &&
146 '' | HEAD
) remote
=HEAD
;;
148 heads
/* | tags
/* | remotes
/* ) remote
="refs/$remote" ;;
149 *) remote
="refs/heads/$remote" ;;
154 heads
/* | tags
/* | remotes
/* ) local="refs/$local" ;;
155 *) local="refs/heads/$local" ;;
158 if local_ref_name
=$
(expr "z$local" : 'zrefs/\(.*\)')
160 git check-ref-format
"$local_ref_name" ||
161 die
"* refusing to create funny ref '$local_ref_name' locally"
163 echo "${dot_prefix}${force}${remote}:${local}"
167 # Returns list of src: (no store), or src:dst (store)
168 get_remote_default_refs_for_fetch
() {
169 data_source
=$
(get_data_source
"$1")
170 case "$data_source" in
174 canon_refs_list_for_fetch
-d "$1" \
175 $
(git for-each-ref
--format='%(refname):')
178 canon_refs_list_for_fetch
-d "$1" \
179 $
(git config
--get-all "remote.$1.fetch") ;;
181 remote_branch
=$
(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
182 case "$remote_branch" in '') remote_branch
=master
;; esac
183 echo "refs/heads/${remote_branch}:refs/heads/$1"
186 canon_refs_list_for_fetch
-d "$1" $
(sed -ne '/^Pull: */{
188 }' "$GIT_DIR/remotes/$1")
191 die
"internal error: get-remote-default-ref-for-fetch $1" ;;
195 get_remote_refs_for_push
() {
197 0) die
"internal error: get-remote-refs-for-push." ;;
198 1) get_remote_default_refs_for_push
"$@" ;;
199 *) shift; echo "$@" ;;
203 get_remote_refs_for_fetch
() {
206 die
"internal error: get-remote-refs-for-fetch." ;;
208 get_remote_default_refs_for_fetch
"$@" ;;
214 if test "$tag_just_seen"
216 echo "refs/tags/${ref}:refs/tags/${ref}"
227 canon_refs_list_for_fetch
"$ref"
233 resolve_alternates
() {
234 # original URL (xxx.git)
235 top_
=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
242 echo "$top_$path/" ;;
244 # relative -- ugly but seems to work.
245 echo "$1/objects/$path/" ;;
247 # exit code may not be caught by the reader.
248 echo "bad alternate: $path"
255 data_source
=$
(get_data_source
"$1")
256 case "$data_source" in
258 uplp
=$
(git config
--get "remote.$1.uploadpack")
259 echo ${uplp:-git-upload-pack}
262 echo "git-upload-pack"