]> git.ipfire.org Git - thirdparty/git.git/blob - git-parse-remote.sh
Merge branch 'kc/gitweb-pathinfo-w-anchor'
[thirdparty/git.git] / git-parse-remote.sh
1 #!/bin/sh
2
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) || :;
6
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}
11 }
12
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)
22 ;;
23 *)
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+\(.*\)')
32 ;;
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
43 .)
44 echo "refs/heads/$remote"
45 ;;
46 *)
47 echo "refs/remotes/$repo/$remote"
48 ;;
49 esac
50 esac
51 }