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 # Called from canon_refs_list_for_fetch -d "$remote", which
94 # is called from get_remote_default_refs_for_fetch to grok
95 # refspecs that are retrieved from the configuration, but not
96 # from get_remote_refs_for_fetch when it deals with refspecs
97 # supplied on the command line. $ls_remote_result has the list
98 # of refs available at remote.
99 expand_refs_wildcard
() {
103 # a non glob pattern is given back as-is.
104 expr "z$lref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev
/null ||
{
109 from
=`expr "z$lref" : 'z\(refs/.*/\)\*:refs/.*/\*$'`
110 to
=`expr "z$lref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'`
112 test "z$lref" = "z$ref" || local_force
='+'
113 echo "$ls_remote_result" |
119 # ignore the ones that do not start with $from
120 mapped
=${name#"$from"}
121 test "z$name" = "z$mapped" && continue
122 echo "${local_force}${name}:${to}${mapped}"
128 # Subroutine to canonicalize remote:local notation.
129 canon_refs_list_for_fetch
() {
130 # If called from get_remote_default_refs_for_fetch
131 # leave the branches in branch.${curr_branch}.merge alone,
132 # or the first one otherwise; add prefix . to the rest
133 # to prevent the secondary branches to be merged by default.
139 shift ; remote
="$1" ; shift
140 if test "$remote" = "$(get_default_remote)"
142 curr_branch
=$
(git-symbolic-ref HEAD | \
143 sed -e 's|^refs/heads/||')
144 merge_branches
=$
(git-repo-config \
145 --get-all "branch.${curr_branch}.merge")
147 set x $
(expand_refs_wildcard
"$@")
155 ref
=$
(expr "z$ref" : 'z+\(.*\)')
159 expr "z$ref" : 'z.*:' >/dev
/null || ref
="${ref}:"
160 remote
=$
(expr "z$ref" : 'z\([^:]*\):')
161 local=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
163 if test -z "$merge_branches"
165 merge_branches
=$remote
168 for merge_branch
in $merge_branches
170 [ "$remote" = "$merge_branch" ] &&
174 if test -z $dot_prefix
180 refs
/heads
/* | refs
/tags
/* | refs
/remotes
/*) ;;
181 heads
/* | tags
/* | remotes
/* ) remote
="refs/$remote" ;;
182 *) remote
="refs/heads/$remote" ;;
186 refs
/heads
/* | refs
/tags
/* | refs
/remotes
/*) ;;
187 heads
/* | tags
/* | remotes
/* ) local="refs/$local" ;;
188 *) local="refs/heads/$local" ;;
191 if local_ref_name
=$
(expr "z$local" : 'zrefs/\(.*\)')
193 git-check-ref-format
"$local_ref_name" ||
194 die
"* refusing to create funny ref '$local_ref_name' locally"
196 echo "${dot_prefix}${force}${remote}:${local}"
198 if test -z "$found_mergeref" -a "$curr_branch"
200 echo >&2 "Warning: No merge candidate found because value of config option
201 \"branch.${curr_branch}.merge\" does not match any remote branch fetched."
205 # Returns list of src: (no store), or src:dst (store)
206 get_remote_default_refs_for_fetch
() {
207 data_source
=$
(get_data_source
"$1")
208 case "$data_source" in
209 '' | config-partial | branches-partial
)
212 canon_refs_list_for_fetch
-d "$1" \
213 $
(git-repo-config
--get-all "remote.$1.fetch") ;;
215 remote_branch
=$
(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
216 case "$remote_branch" in '') remote_branch
=master
;; esac
217 echo "refs/heads/${remote_branch}:refs/heads/$1"
220 canon_refs_list_for_fetch
-d "$1" $
(sed -ne '/^Pull: */{
222 }' "$GIT_DIR/remotes/$1")
225 die
"internal error: get-remote-default-ref-for-push $1" ;;
229 get_remote_refs_for_push
() {
231 0) die
"internal error: get-remote-refs-for-push." ;;
232 1) get_remote_default_refs_for_push
"$@" ;;
233 *) shift; echo "$@" ;;
237 get_remote_refs_for_fetch
() {
240 die
"internal error: get-remote-refs-for-fetch." ;;
242 get_remote_default_refs_for_fetch
"$@" ;;
248 if test "$tag_just_seen"
250 echo "refs/tags/${ref}:refs/tags/${ref}"
261 canon_refs_list_for_fetch
"$ref"
267 resolve_alternates
() {
268 # original URL (xxx.git)
269 top_
=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
276 echo "$top_$path/" ;;
278 # relative -- ugly but seems to work.
279 echo "$1/objects/$path/" ;;
281 # exit code may not be caught by the reader.
282 echo "bad alternate: $path"