]>
Commit | Line | Data |
---|---|---|
ac4b0cff JH |
1 | #!/bin/sh |
2 | ||
e8cc80d0 JH |
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. | |
7bd93c1c | 5 | GIT_DIR=$(git rev-parse -q --git-dir) || :; |
ac4b0cff | 6 | |
648ad18f | 7 | get_default_remote () { |
5be60078 JH |
8 | curr_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||') |
9 | origin=$(git config --get "branch.$curr_branch.remote") | |
648ad18f SB |
10 | echo ${origin:-origin} |
11 | } | |
12 | ||
97af7ff0 SB |
13 | get_remote_merge_branch () { |
14 | case "$#" in | |
15 | 0|1) | |
e9460a66 SB |
16 | origin="$1" |
17 | default=$(get_default_remote) | |
18 | test -z "$origin" && origin=$default | |
f864f261 | 19 | curr_branch=$(git symbolic-ref -q HEAD) && |
e9460a66 SB |
20 | [ "$origin" = "$default" ] && |
21 | echo $(git for-each-ref --format='%(upstream)' $curr_branch) | |
22 | ;; | |
97af7ff0 SB |
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 | |
fe249b42 MZ |
42 | [ -n "$remote" ] && case "$repo" in |
43 | .) | |
44 | echo "refs/heads/$remote" | |
45 | ;; | |
46 | *) | |
47 | echo "refs/remotes/$repo/$remote" | |
48 | ;; | |
49 | esac | |
97af7ff0 SB |
50 | esac |
51 | } |