Code

i18n: mark clone nonexistent repository message for translation
[git.git] / git-parse-remote.sh
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)
9         curr_branch="${curr_branch#refs/heads/}"
10         origin=$(git config --get "branch.$curr_branch.remote")
11         echo ${origin:-origin}
12 }
14 get_remote_merge_branch () {
15         case "$#" in
16         0|1)
17             origin="$1"
18             default=$(get_default_remote)
19             test -z "$origin" && origin=$default
20             curr_branch=$(git symbolic-ref -q HEAD) &&
21             [ "$origin" = "$default" ] &&
22             echo $(git for-each-ref --format='%(upstream)' $curr_branch)
23             ;;
24         *)
25             repo=$1
26             shift
27             ref=$1
28             # FIXME: It should return the tracking branch
29             #        Currently only works with the default mapping
30             case "$ref" in
31             +*)
32                 ref=$(expr "z$ref" : 'z+\(.*\)')
33                 ;;
34             esac
35             expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
36             remote=$(expr "z$ref" : 'z\([^:]*\):')
37             case "$remote" in
38             '' | HEAD ) remote=HEAD ;;
39             heads/*) remote=${remote#heads/} ;;
40             refs/heads/*) remote=${remote#refs/heads/} ;;
41             refs/* | tags/* | remotes/* ) remote=
42             esac
43             [ -n "$remote" ] && case "$repo" in
44                 .)
45                     echo "refs/heads/$remote"
46                     ;;
47                 *)
48                     echo "refs/remotes/$repo/$remote"
49                     ;;
50             esac
51         esac
52 }