# This is a shell library to calculate the remote repository and # upstream branch that should be pulled by "git pull" from the current # branch. # git-ls-remote could be called from outside a git managed repository; # this would fail in that case and would issue an error message. setvar GIT_DIR = $(git rev-parse -q --git-dir) || :; proc get_default_remote { setvar curr_branch = $(git symbolic-ref -q HEAD) setvar curr_branch = "${curr_branch#refs/heads/}" setvar origin = $(git config --get "branch.$curr_branch.remote") echo ${origin:-origin} } proc get_remote_merge_branch { case (#) { 0|1 { setvar origin = "$1" setvar default = $(get_default_remote) test -z $origin && setvar origin = "$default" setvar curr_branch = $(git symbolic-ref -q HEAD) && test $origin = $default && echo $(git for-each-ref --format='%(upstream)' $curr_branch) } * { setvar repo = "$1" shift setvar ref = "$1" # FIXME: It should return the tracking branch # Currently only works with the default mapping case (ref) { +* { setvar ref = $(expr "z$ref" : 'z+\(.*\)') } } expr "z$ref" : 'z.*:' >/dev/null || setvar ref = ""${ref}:"" setvar remote = $(expr "z$ref" : 'z\([^:]*\):') case (remote) { '' | HEAD { setvar remote = 'HEAD' } heads/* { setvar remote = ${remote#heads/} } refs/heads/* { setvar remote = ${remote#refs/heads/} } refs/* | tags/* | remotes/* { setvar remote = '' } } test -n $remote && case (repo) { . { echo "refs/heads/$remote" } * { echo "refs/remotes/$repo/$remote" } } } } } proc error_on_missing_default_upstream { setvar cmd = "$1" setvar op_type = "$2" setvar op_prep = "$3" # FIXME: op_prep is no longer used setvar example = "$4" setvar branch_name = $(git symbolic-ref -q HEAD) setvar display_branch_name = "${branch_name#refs/heads/}" # If there's only one remote, use that in the suggestion setvar remote = "$(gettext "")" setvar branch = "$(gettext "")" if test $(git remote | wc -l) = 1 { setvar remote = $(git remote) } if test -z $branch_name { gettextln "You are not currently on a branch." } else { gettextln "There is no tracking information for the current branch." } case (op_type) { rebase { gettextln "Please specify which branch you want to rebase against." } merge { gettextln "Please specify which branch you want to merge with." } * { echo >&2 "BUG: unknown operation type: $op_type>&2 "BUG: unknown operation type: $op_type" exit 1 } } eval_gettextln "See git-\${cmd}(1) for details." echo echo " $example" echo if test -n $branch_name { gettextln "If you wish to set tracking information for this branch you can do so with:" echo echo " git branch --set-upstream-to=$remote/$branch $display_branch_name" echo } exit 1 }