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 -q --git-dir) || :;
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)
59 curr_branch="${cur_branch#refs/heads/}"
60 origin=$(git config --get "branch.$curr_branch.remote")
61 echo ${origin:-origin}
64 get_remote_merge_branch () {
68 default=$(get_default_remote)
69 test -z "$origin" && origin=$default
70 curr_branch=$(git symbolic-ref -q HEAD) &&
71 [ "$origin" = "$default" ] &&
72 echo $(git for-each-ref --format='%(upstream)' $curr_branch)
78 # FIXME: It should return the tracking branch
79 # Currently only works with the default mapping
82 ref=$(expr "z$ref" : 'z+\(.*\)')
85 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
86 remote=$(expr "z$ref" : 'z\([^:]*\):')
88 '' | HEAD ) remote=HEAD ;;
89 heads/*) remote=${remote#heads/} ;;
90 refs/heads/*) remote=${remote#refs/heads/} ;;
91 refs/* | tags/* | remotes/* ) remote=
93 [ -n "$remote" ] && case "$repo" in
95 echo "refs/heads/$remote"
98 echo "refs/remotes/$repo/$remote"