1 # This is a shell library to calculate the remote repository and
2 # upstream branch that should be pulled by "git pull" from the current
5 # git-ls-remote could be called from outside a git managed repository;
6 # this would fail in that case and would issue an error message.
7 GIT_DIR=$(git rev-parse -q --git-dir) || :;
9 get_default_remote () {
10 curr_branch=$(git symbolic-ref -q HEAD)
11 curr_branch="${curr_branch#refs/heads/}"
12 origin=$(git config --get "branch.$curr_branch.remote")
13 echo ${origin:-origin}
16 get_remote_merge_branch () {
20 default=$(get_default_remote)
21 test -z "$origin" && origin=$default
22 curr_branch=$(git symbolic-ref -q HEAD) &&
23 [ "$origin" = "$default" ] &&
24 echo $(git for-each-ref --format='%(upstream)' $curr_branch)
30 # FIXME: It should return the tracking branch
31 # Currently only works with the default mapping
34 ref=$(expr "z$ref" : 'z+\(.*\)')
37 expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
38 remote=$(expr "z$ref" : 'z\([^:]*\):')
40 '' | HEAD ) remote=HEAD ;;
41 heads/*) remote=${remote#heads/} ;;
42 refs/heads/*) remote=${remote#refs/heads/} ;;
43 refs/* | tags/* | remotes/* ) remote=
45 [ -n "$remote" ] && case "$repo" in
47 echo "refs/heads/$remote"
50 echo "refs/remotes/$repo/$remote"
56 error_on_missing_default_upstream () {
59 op_prep="$3" # FIXME: op_prep is no longer used
61 branch_name=$(git symbolic-ref -q HEAD)
62 display_branch_name="${branch_name#refs/heads/}"
63 # If there's only one remote, use that in the suggestion
64 remote="$(gettext "<remote>")"
65 branch="$(gettext "<branch>")"
66 if test $(git remote | wc -l) = 1
71 if test -z "$branch_name"
73 gettextln "You are not currently on a branch."
75 gettextln "There is no tracking information for the current branch."
79 gettextln "Please specify which branch you want to rebase against."
82 gettextln "Please specify which branch you want to merge with."
85 echo >&2 "BUG: unknown operation type: $op_type"
89 eval_gettextln "See git-\${cmd}(1) for details."
93 if test -n "$branch_name"
95 gettextln "If you wish to set tracking information for this branch you can do so with:"
97 echo " git branch --set-upstream-to=$remote/$branch $display_branch_name"