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
) ||
:;
13 if test "$(git-repo-config --get "remote.
$1.url
")"
16 elif test -f "$GIT_DIR/remotes/$1"
19 elif test -f "$GIT_DIR/branches/$1"
29 data_source
=$
(get_data_source
"$1")
30 case "$data_source" in
35 git-repo-config
--get "remote.$1.url"
41 }' "$GIT_DIR/remotes/$1"
44 sed -e 's/#.*//' "$GIT_DIR/branches/$1"
47 die
"internal error: get-remote-url $1" ;;
51 get_default_remote
() {
52 curr_branch
=$
(git-symbolic-ref HEAD |
sed -e 's|^refs/heads/||')
53 origin
=$
(git-repo-config
--get "branch.$curr_branch.remote")
54 echo ${origin:-origin}
57 get_remote_default_refs_for_push
() {
58 data_source
=$
(get_data_source
"$1")
59 case "$data_source" in
61 ;; # no default push mapping, just send matching refs.
63 git-repo-config
--get-all "remote.$1.push" ;;
67 }' "$GIT_DIR/remotes/$1" ;;
69 die
"internal error: get-remote-default-ref-for-push $1" ;;
73 # Called from canon_refs_list_for_fetch -d "$remote", which
74 # is called from get_remote_default_refs_for_fetch to grok
75 # refspecs that are retrieved from the configuration, but not
76 # from get_remote_refs_for_fetch when it deals with refspecs
77 # supplied on the command line. $ls_remote_result has the list
78 # of refs available at remote.
79 expand_refs_wildcard
() {
83 # a non glob pattern is given back as-is.
84 expr "z$lref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev
/null ||
{
89 from
=`expr "z$lref" : 'z\(refs/.*/\)\*:refs/.*/\*$'`
90 to
=`expr "z$lref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'`
92 test "z$lref" = "z$ref" || local_force
='+'
93 echo "$ls_remote_result" |
99 # ignore the ones that do not start with $from
100 mapped
=${name#"$from"}
101 test "z$name" = "z$mapped" && continue
102 echo "${local_force}${name}:${to}${mapped}"
108 # Subroutine to canonicalize remote:local notation.
109 canon_refs_list_for_fetch
() {
110 # If called from get_remote_default_refs_for_fetch
111 # leave the branches in branch.${curr_branch}.merge alone,
112 # or the first one otherwise; add prefix . to the rest
113 # to prevent the secondary branches to be merged by default.
118 shift ; remote
="$1" ; shift
119 set x $
(expand_refs_wildcard
"$@")
121 if test "$remote" = "$(get_default_remote)"
123 curr_branch
=$
(git-symbolic-ref HEAD | \
124 sed -e 's|^refs/heads/||')
125 merge_branches
=$
(git-repo-config \
126 --get-all "branch.${curr_branch}.merge")
134 ref
=$
(expr "z$ref" : 'z+\(.*\)')
138 expr "z$ref" : 'z.*:' >/dev
/null || ref
="${ref}:"
139 remote
=$
(expr "z$ref" : 'z\([^:]*\):')
140 local=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
142 if test -z "$merge_branches"
144 merge_branches
=$remote
147 for merge_branch
in $merge_branches
149 if test "$remote" = "$merge_branch" ||
150 test "$local" = "$merge_branch"
159 refs
/heads
/* | refs
/tags
/* | refs
/remotes
/*) ;;
160 heads
/* | tags
/* | remotes
/* ) remote
="refs/$remote" ;;
161 *) remote
="refs/heads/$remote" ;;
165 refs
/heads
/* | refs
/tags
/* | refs
/remotes
/*) ;;
166 heads
/* | tags
/* | remotes
/* ) local="refs/$local" ;;
167 *) local="refs/heads/$local" ;;
170 if local_ref_name
=$
(expr "z$local" : 'zrefs/\(.*\)')
172 git-check-ref-format
"$local_ref_name" ||
173 die
"* refusing to create funny ref '$local_ref_name' locally"
175 echo "${dot_prefix}${force}${remote}:${local}"
179 # Returns list of src: (no store), or src:dst (store)
180 get_remote_default_refs_for_fetch
() {
181 data_source
=$
(get_data_source
"$1")
182 case "$data_source" in
186 canon_refs_list_for_fetch
-d "$1" \
187 $
(git-repo-config
--get-all "remote.$1.fetch") ;;
189 remote_branch
=$
(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
190 case "$remote_branch" in '') remote_branch
=master
;; esac
191 echo "refs/heads/${remote_branch}:refs/heads/$1"
194 canon_refs_list_for_fetch
-d "$1" $
(sed -ne '/^Pull: */{
196 }' "$GIT_DIR/remotes/$1")
199 die
"internal error: get-remote-default-ref-for-push $1" ;;
203 get_remote_refs_for_push
() {
205 0) die
"internal error: get-remote-refs-for-push." ;;
206 1) get_remote_default_refs_for_push
"$@" ;;
207 *) shift; echo "$@" ;;
211 get_remote_refs_for_fetch
() {
214 die
"internal error: get-remote-refs-for-fetch." ;;
216 get_remote_default_refs_for_fetch
"$@" ;;
222 if test "$tag_just_seen"
224 echo "refs/tags/${ref}:refs/tags/${ref}"
235 canon_refs_list_for_fetch
"$ref"
241 resolve_alternates
() {
242 # original URL (xxx.git)
243 top_
=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
250 echo "$top_$path/" ;;
252 # relative -- ugly but seems to work.
253 echo "$1/objects/$path/" ;;
255 # exit code may not be caught by the reader.
256 echo "bad alternate: $path"