Merge branch 'master' into next
[git/dscho.git] / git-parse-remote.sh
blobac41ad665c8163c1cc80eb11f03c95109b2b2488
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
53 error_on_missing_default_upstream () {
54 cmd="$1"
55 op_type="$2"
56 op_prep="$3"
57 example="$4"
58 branch_name=$(git symbolic-ref -q HEAD)
59 if test -z "$branch_name"
60 then
61 echo "You are not currently on a branch, so I cannot use any
62 'branch.<branchname>.merge' in your configuration file.
63 Please specify which branch you want to $op_type $op_prep on the command
64 line and try again (e.g. '$example').
65 See git-${cmd}(1) for details."
66 else
67 echo "You asked me to $cmd without telling me which branch you
68 want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
69 your configuration file does not tell me, either. Please
70 specify which branch you want to use on the command line and
71 try again (e.g. '$example').
72 See git-${cmd}(1) for details.
74 If you often $op_type $op_prep the same branch, you may want to
75 use something like the following in your configuration file:
76 [branch \"${branch_name#refs/heads/}\"]
77 remote = <nickname>
78 merge = <remote-ref>"
79 test rebase = "$op_type" &&
80 echo " rebase = true"
81 echo "
82 [remote \"<nickname>\"]
83 url = <url>
84 fetch = <refspec>
86 See git-config(1) for details."
88 exit 1