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_remote_default_refs_for_push
() {
72 data_source
=$
(get_data_source
"$1")
73 case "$data_source" in
74 '' | config-partial | branches | branches-partial
)
75 ;; # no default push mapping, just send matching refs.
77 git-repo-config
--get-all "remote.$1.push" ;;
81 }' "$GIT_DIR/remotes/$1" ;;
83 die
"internal error: get-remote-default-ref-for-push $1" ;;
87 # Subroutine to canonicalize remote:local notation.
88 canon_refs_list_for_fetch
() {
89 # Leave only the first one alone; add prefix . to the rest
90 # to prevent the secondary branches to be merged by default.
97 ref
=$
(expr "z$ref" : 'z+\(.*\)')
101 expr "z$ref" : 'z.*:' >/dev
/null || ref
="${ref}:"
102 remote
=$
(expr "z$ref" : 'z\([^:]*\):')
103 local=$
(expr "z$ref" : 'z[^:]*:\(.*\)')
106 refs
/heads
/* | refs
/tags
/* | refs
/remotes
/*) ;;
107 heads
/* | tags
/* | remotes
/* ) remote
="refs/$remote" ;;
108 *) remote
="refs/heads/$remote" ;;
112 refs
/heads
/* | refs
/tags
/* | refs
/remotes
/*) ;;
113 heads
/* | tags
/* | remotes
/* ) local="refs/$local" ;;
114 *) local="refs/heads/$local" ;;
117 if local_ref_name
=$
(expr "z$local" : 'zrefs/\(.*\)')
119 git-check-ref-format
"$local_ref_name" ||
120 die
"* refusing to create funny ref '$local_ref_name' locally"
122 echo "${dot_prefix}${force}${remote}:${local}"
127 # Returns list of src: (no store), or src:dst (store)
128 get_remote_default_refs_for_fetch
() {
129 data_source
=$
(get_data_source
"$1")
130 case "$data_source" in
131 '' | config-partial | branches-partial
)
134 canon_refs_list_for_fetch \
135 $
(git-repo-config
--get-all "remote.$1.fetch") ;;
137 remote_branch
=$
(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
138 case "$remote_branch" in '') remote_branch
=master
;; esac
139 echo "refs/heads/${remote_branch}:refs/heads/$1"
142 # This prefixes the second and later default refspecs
143 # with a '.', to signal git-fetch to mark them
145 canon_refs_list_for_fetch $
(sed -ne '/^Pull: */{
147 }' "$GIT_DIR/remotes/$1")
150 die
"internal error: get-remote-default-ref-for-push $1" ;;
154 get_remote_refs_for_push
() {
156 0) die
"internal error: get-remote-refs-for-push." ;;
157 1) get_remote_default_refs_for_push
"$@" ;;
158 *) shift; echo "$@" ;;
162 get_remote_refs_for_fetch
() {
165 die
"internal error: get-remote-refs-for-fetch." ;;
167 get_remote_default_refs_for_fetch
"$@" ;;
173 if test "$tag_just_seen"
175 echo "refs/tags/${ref}:refs/tags/${ref}"
186 canon_refs_list_for_fetch
"$ref"
192 resolve_alternates
() {
193 # original URL (xxx.git)
194 top_
=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
201 echo "$top_$path/" ;;
203 # relative -- ugly but seems to work.
204 echo "$1/objects/$path/" ;;
206 # exit code may not be caught by the reader.
207 echo "bad alternate: $path"