Merge branch 'maint'
[alt-git.git] / git-parse-remote.sh
blobe7013f7ba72a64ab24b991846755b6d6c068b37a
1 #!/bin/sh
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 () {
14 case "$#" in
15 0|1)
16 origin="$1"
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)
24 repo=$1
25 shift
26 ref=$1
27 # FIXME: It should return the tracking branch
28 # Currently only works with the default mapping
29 case "$ref" in
30 +*)
31 ref=$(expr "z$ref" : 'z+\(.*\)')
33 esac
34 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
35 remote=$(expr "z$ref" : 'z\([^:]*\):')
36 case "$remote" in
37 '' | HEAD ) remote=HEAD ;;
38 heads/*) remote=${remote#heads/} ;;
39 refs/heads/*) remote=${remote#refs/heads/} ;;
40 refs/* | tags/* | remotes/* ) remote=
41 esac
42 [ -n "$remote" ] && case "$repo" in
44 echo "refs/heads/$remote"
47 echo "refs/remotes/$repo/$remote"
49 esac
50 esac