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) || :;
7 get_default_remote () {
8 curr_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
9 origin=$(git config --get "branch.$curr_branch.remote")
10 echo ${origin:-origin}
13 get_remote_merge_branch () {
17 default=$(get_default_remote)
18 test -z "$origin" && origin=$default
19 curr_branch=$(git symbolic-ref -q HEAD) &&
20 [ "$origin" = "$default" ] &&
21 echo $(git for-each-ref --format='%(upstream)' $curr_branch)
27 # FIXME: It should return the tracking branch
28 # Currently only works with the default mapping
31 ref=$(expr "z$ref" : 'z+\(.*\)')
34 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
35 remote=$(expr "z$ref" : 'z\([^:]*\):')
37 '' | HEAD ) remote=HEAD ;;
38 heads/*) remote=${remote#heads/} ;;
39 refs/heads/*) remote=${remote#refs/heads/} ;;
40 refs/* | tags/* | remotes/* ) remote=
42 [ -n "$remote" ] && case "$repo" in
44 echo "refs/heads/$remote"
47 echo "refs/remotes/$repo/$remote"